Exception: JSONRPC::Error
- Inherits:
-
StandardError
- Object
- StandardError
- JSONRPC::Error
- Defined in:
- lib/jsonrpc/error.rb
Overview
A JSON-RPC 2.0 Error object
When a rpc call encounters an error, the Response Object must contain an Error object with specific properties according to the JSON-RPC 2.0 specification.
Direct Known Subclasses
InternalError, InvalidParamsError, InvalidRequestError, MethodNotFoundError, ParseError
Instance Attribute Summary collapse
-
#code ⇒ Integer
Error code indicating the error type.
-
#data ⇒ Hash, ...
Additional information about the error (optional).
-
#message ⇒ String
Short description of the error.
-
#request_id ⇒ String, ...
The request identifier (optional for notifications).
Instance Method Summary collapse
-
#initialize(message, code:, data: nil, request_id: nil) ⇒ Error
constructor
Creates a new JSON-RPC 2.0 Error object.
-
#to_h ⇒ Hash
Converts the error to a JSON-compatible Hash.
-
#to_json ⇒ String
Converts the error to JSON.
-
#to_response ⇒ Hash
Converts the error to a complete JSON-RPC response.
Constructor Details
#initialize(message, code:, data: nil, request_id: nil) ⇒ Error
Creates a new JSON-RPC 2.0 Error object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jsonrpc/error.rb', line 94 def initialize(, code:, data: nil, request_id: nil) super() validate_code(code) () @code = code @message = @data = data @request_id = request_id end |
Instance Attribute Details
#code ⇒ Integer
Error code indicating the error type
45 46 47 |
# File 'lib/jsonrpc/error.rb', line 45 def code @code end |
#data ⇒ Hash, ...
Additional information about the error (optional)
73 74 75 |
# File 'lib/jsonrpc/error.rb', line 73 def data @data end |
#message ⇒ String
Short description of the error
59 60 61 |
# File 'lib/jsonrpc/error.rb', line 59 def @message end |
#request_id ⇒ String, ...
The request identifier (optional for notifications)
31 32 33 |
# File 'lib/jsonrpc/error.rb', line 31 def request_id @request_id end |
Instance Method Details
#to_h ⇒ Hash
Converts the error to a JSON-compatible Hash
115 116 117 118 119 |
# File 'lib/jsonrpc/error.rb', line 115 def to_h hash = { code:, message: } hash[:data] = data unless data.nil? hash end |
#to_json ⇒ String
Converts the error to JSON
130 131 132 |
# File 'lib/jsonrpc/error.rb', line 130 def to_json(*) MultiJson.dump(to_h, *) end |