Exception: Msf::RPC::JSON::ErrorResponse

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

Instance Attribute Summary collapse

Attributes inherited from ClientError

#response

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, code:, message:, data: nil, response: nil) ⇒ ErrorResponse

Instantiate an ErrorResponse object.

Parameters:

  • id (Integer, String, NilClass)

    It MUST be the same as the value of the id member in the Request Object. If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.

  • 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.

  • response (Hash) (defaults to: nil)

    A response hash. The default value is nil.


218
219
220
221
222
223
224
# File 'lib/msf/core/rpc/json/error.rb', line 218

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code


173
174
175
# File 'lib/msf/core/rpc/json/error.rb', line 173

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data


175
176
177
# File 'lib/msf/core/rpc/json/error.rb', line 175

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id


172
173
174
# File 'lib/msf/core/rpc/json/error.rb', line 172

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message


174
175
176
# File 'lib/msf/core/rpc/json/error.rb', line 174

def message
  @message
end

Class Method Details

.parse(response, symbolize_names: true) ⇒ Object

Parse response and return a new ErrorResponse instance.

Parameters:

  • response (Hash)

    A response hash.

  • symbolize_names (Boolean) (defaults to: true)

    If true, symbols are used for the names (keys) when processing JSON objects; otherwise, strings are used. Default: true


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/msf/core/rpc/json/error.rb', line 182

def self.parse(response, symbolize_names: true)
  id_key = symbolize_names ? :id : :id.to_s
  error_key = symbolize_names ? :error : :error.to_s
  code_key = symbolize_names ? :code : :code.to_s
  message_key = symbolize_names ? :message : :message.to_s
  data_key = symbolize_names ? :data : :data.to_s

  id = response[id_key]
  error = response[error_key]

  if !error.nil?
    code = error[code_key]
    message = error[message_key]
    data = error[data_key]
  else
    code = nil
    message = nil
    data = nil
  end

  ErrorResponse.new(id: id, code: code, message: message, data: data, response: response)
end