Class: JSONRPCOverMQTT::JSONRPC::ErrorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/json_rpc_over_mqtt_example/json_rpc/error_response.rb

Constant Summary collapse

METHOD_NOT_FOUND =
{code: "-32601", message: "Method not found"}
PARSE_ERROR =
{code: "-32602", message: "JSON parse error"}

Class Method Summary collapse

Class Method Details

.generate_response(json_rpc_id, error_response) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/json_rpc_over_mqtt_example/json_rpc/error_response.rb', line 9

def self.generate_response(json_rpc_id, error_response)
  ::JSON.generate({
    jsonrpc: VERSION,
    id: json_rpc_id,
    error: error_response
  })
end

.method_not_found(json_rpc_id) ⇒ Object



17
18
19
# File 'lib/json_rpc_over_mqtt_example/json_rpc/error_response.rb', line 17

def self.method_not_found(json_rpc_id)
  generate_response(json_rpc_id, METHOD_NOT_FOUND)
end

.parse_errorObject



21
22
23
# File 'lib/json_rpc_over_mqtt_example/json_rpc/error_response.rb', line 21

def self.parse_error
  generate_response(nil, PARSE_ERROR)
end