Module: JSONRPC::RPCObject
- Defined in:
- lib/jsonrpc/rpc_object.rb
Overview
Class Method Summary collapse
- .detailed_internal_error(exception, request_id: nil) ⇒ JSONRPC::ErrorResponse
- .error(data = {}, code: JSONRPC::ERRORS[:application_error][:code], message: JSONRPC::ERRORS[:application_error][:message], request_id: nil) ⇒ JSONRPC::ErrorResponse (also: application_error)
- .internal_error(*error_codes, error_context: {}, request_id: nil) ⇒ JSONRPC::ErrorResponse
- .invalid_params_error(data = {}, request_id: nil) ⇒ JSONRPC::ErrorResponse
- .invalid_request_error(data = {}, request_id: nil) ⇒ JSONRPC::ErrorResponse
- .jsonrpc_specification_violation_error(request_id: nil) ⇒ JSONRPC::ErrorResponse
- .method_not_found_error(request_id: nil) ⇒ JSONRPC::ErrorResponse
- .notification(jsonrpc: '2.0', method:, params:) ⇒ JSONRPC::Notification
- .parse_error ⇒ JSONRPC::ErrorResponse
- .request(jsonrpc: '2.0', method:, params:, id:) ⇒ JSONRPC::Request
- .response(result = {}, request_id: nil) ⇒ JSONRPC::Response, NilClass
Class Method Details
.detailed_internal_error(exception, request_id: nil) ⇒ JSONRPC::ErrorResponse
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/jsonrpc/rpc_object.rb', line 155 def detailed_internal_error(exception, request_id: nil) internal_error( error_context: { error_class: exception.class, error_message: exception., error_backtrace: exception.backtrace, error_object: exception }, request_id: ) end |
.error(data = {}, code: JSONRPC::ERRORS[:application_error][:code], message: JSONRPC::ERRORS[:application_error][:message], request_id: nil) ⇒ JSONRPC::ErrorResponse Also known as: application_error
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jsonrpc/rpc_object.rb', line 29 def error( data = {}, code: JSONRPC::ERRORS[:application_error][:code], message: JSONRPC::ERRORS[:application_error][:message], request_id: nil ) JSONRPC::ErrorResponse.new( jsonrpc: '2.0', error: { code:, message:, data: }, id: request_id ) end |
.internal_error(*error_codes, error_context: {}, request_id: nil) ⇒ JSONRPC::ErrorResponse
140 141 142 143 144 145 146 147 |
# File 'lib/jsonrpc/rpc_object.rb', line 140 def internal_error(*error_codes, error_context: {}, request_id: nil) error( { error_codes:, error_context: }, code: JSONRPC::ERRORS[:internal_error][:code], message: JSONRPC::ERRORS[:internal_error][:message], request_id: ) end |
.invalid_params_error(data = {}, request_id: nil) ⇒ JSONRPC::ErrorResponse
124 125 126 127 128 129 130 131 |
# File 'lib/jsonrpc/rpc_object.rb', line 124 def invalid_params_error(data = {}, request_id: nil) error( data, code: JSONRPC::ERRORS[:invalid_params][:code], message: JSONRPC::ERRORS[:invalid_params][:message], request_id: ) end |
.invalid_request_error(data = {}, request_id: nil) ⇒ JSONRPC::ErrorResponse
72 73 74 75 76 77 78 79 |
# File 'lib/jsonrpc/rpc_object.rb', line 72 def invalid_request_error(data = {}, request_id: nil) error( data, code: JSONRPC::ERRORS[:invalid_request][:code], message: JSONRPC::ERRORS[:invalid_request][:message], request_id: ) end |
.jsonrpc_specification_violation_error(request_id: nil) ⇒ JSONRPC::ErrorResponse
97 98 99 100 101 102 103 |
# File 'lib/jsonrpc/rpc_object.rb', line 97 def jsonrpc_specification_violation_error(request_id: nil) error( code: JSONRPC::ERRORS[:jsonrpc_specification_violation][:code], message: JSONRPC::ERRORS[:jsonrpc_specification_violation][:message], request_id: ) end |
.method_not_found_error(request_id: nil) ⇒ JSONRPC::ErrorResponse
110 111 112 113 114 115 116 |
# File 'lib/jsonrpc/rpc_object.rb', line 110 def method_not_found_error(request_id: nil) error( code: JSONRPC::ERRORS[:method_not_found][:code], message: JSONRPC::ERRORS[:method_not_found][:message], request_id: ) end |
.notification(jsonrpc: '2.0', method:, params:) ⇒ JSONRPC::Notification
62 63 64 |
# File 'lib/jsonrpc/rpc_object.rb', line 62 def notification(jsonrpc: '2.0', method:, params:) JSONRPC::Notification.new(jsonrpc:, method:, params:) end |
.parse_error ⇒ JSONRPC::ErrorResponse
85 86 87 88 89 90 |
# File 'lib/jsonrpc/rpc_object.rb', line 85 def parse_error error( code: JSONRPC::ERRORS[:parse_error][:code], message: JSONRPC::ERRORS[:parse_error][:message] ) end |
.request(jsonrpc: '2.0', method:, params:, id:) ⇒ JSONRPC::Request
51 52 53 |
# File 'lib/jsonrpc/rpc_object.rb', line 51 def request(jsonrpc: '2.0', method:, params:, id:) JSONRPC::Request.new(jsonrpc:, method:, params:, id:) end |
.response(result = {}, request_id: nil) ⇒ JSONRPC::Response, NilClass
14 15 16 17 18 19 |
# File 'lib/jsonrpc/rpc_object.rb', line 14 def response(result = {}, request_id: nil) return if request_id == nil # NOTE: nil is treated as no result # @type var request_id: untyped JSONRPC::Response.new(jsonrpc: '2.0', result:, id: request_id) end |