Exception: Msf::RPC::JSON::RpcError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/msf/core/rpc/json/error.rb

Overview

Base class for all Msf::RPC::JSON exceptions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message, data: nil) ⇒ RpcError

Instantiate an RpcError object.

Parameters:

  • code (Integer)

    A Number that indicates the error type that occurred.

  • message (String)

    A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.

  • data (Object) (defaults to: nil)

    A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.). The default value is nil.



51
52
53
54
55
56
# File 'lib/msf/core/rpc/json/error.rb', line 51

def initialize(code, message, data: nil)
  super(message)
  @code = code
  @message = message
  @data = data
end

Instance Attribute Details

#codeObject (readonly)

Code Message Meaning -32700 Parse error Invalid JSON was received by the server. An error

occurred on the server while parsing the JSON text.

-32600 Invalid Request The JSON sent is not a valid Request object. -32601 Method not found The method does not exist / is not available. -32602 Invalid params Invalid method parameter(s). -32603 Internal error Internal JSON-RPC error. -32000 to -32099 Server error Reserved for implementation-defined server-errors.



38
39
40
# File 'lib/msf/core/rpc/json/error.rb', line 38

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data.



40
41
42
# File 'lib/msf/core/rpc/json/error.rb', line 40

def data
  @data
end

#messageObject (readonly)

Returns the value of attribute message.



39
40
41
# File 'lib/msf/core/rpc/json/error.rb', line 39

def message
  @message
end

Instance Method Details

#to_hObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/msf/core/rpc/json/error.rb', line 58

def to_h
  hash = {
      code: @code,
      message: @message
  }

  # process data member
  unless @data.nil?
    if @data.is_a?(String) || @data.kind_of?(Numeric) || @data.is_a?(Array) || @data.is_a?(Hash)
      hash[:data] = @data
    elsif @data.respond_to?(:to_h)
      hash[:data] = @data.to_h
    else
      hash[:data] = @data.to_s
    end
  end

  hash
end