Exception: AgentClientProtocol::Error
- Inherits:
-
StandardError
- Object
- StandardError
- AgentClientProtocol::Error
- Defined in:
- lib/agent_client_protocol/error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
- .auth_required(data = nil) ⇒ Object
- .from_h(hash) ⇒ Object
- .internal_error(data = nil) ⇒ Object
- .invalid_params(data = nil) ⇒ Object
- .invalid_request(data = nil) ⇒ Object
- .method_not_found(data = nil) ⇒ Object
- .parse_error(data = nil) ⇒ Object
- .request_cancelled(data = nil) ⇒ Object
- .resource_not_found(uri = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(code:, message: nil, data: nil) ⇒ Error
constructor
A new instance of Error.
- #to_h ⇒ Object
Constructor Details
#initialize(code:, message: nil, data: nil) ⇒ Error
Returns a new instance of Error.
35 36 37 38 39 |
# File 'lib/agent_client_protocol/error.rb', line 35 def initialize(code:, message: nil, data: nil) @code = Integer(code) @data = data super( || ErrorCode.(@code)) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
33 34 35 |
# File 'lib/agent_client_protocol/error.rb', line 33 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
33 34 35 |
# File 'lib/agent_client_protocol/error.rb', line 33 def data @data end |
Class Method Details
.auth_required(data = nil) ⇒ Object
84 85 86 |
# File 'lib/agent_client_protocol/error.rb', line 84 def auth_required(data = nil) new(code: ErrorCode::AUTH_REQUIRED, data: data) end |
.from_h(hash) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/agent_client_protocol/error.rb', line 51 def from_h(hash) normalized = stringify_keys(hash) new( code: normalized.fetch("code"), message: normalized["message"], data: normalized["data"] ) end |
.internal_error(data = nil) ⇒ Object
76 77 78 |
# File 'lib/agent_client_protocol/error.rb', line 76 def internal_error(data = nil) new(code: ErrorCode::INTERNAL_ERROR, data: data) end |
.invalid_params(data = nil) ⇒ Object
72 73 74 |
# File 'lib/agent_client_protocol/error.rb', line 72 def invalid_params(data = nil) new(code: ErrorCode::INVALID_PARAMS, data: data) end |
.invalid_request(data = nil) ⇒ Object
64 65 66 |
# File 'lib/agent_client_protocol/error.rb', line 64 def invalid_request(data = nil) new(code: ErrorCode::INVALID_REQUEST, data: data) end |
.method_not_found(data = nil) ⇒ Object
68 69 70 |
# File 'lib/agent_client_protocol/error.rb', line 68 def method_not_found(data = nil) new(code: ErrorCode::METHOD_NOT_FOUND, data: data) end |
.parse_error(data = nil) ⇒ Object
60 61 62 |
# File 'lib/agent_client_protocol/error.rb', line 60 def parse_error(data = nil) new(code: ErrorCode::PARSE_ERROR, data: data) end |
.request_cancelled(data = nil) ⇒ Object
80 81 82 |
# File 'lib/agent_client_protocol/error.rb', line 80 def request_cancelled(data = nil) new(code: ErrorCode::REQUEST_CANCELLED, data: data) end |
.resource_not_found(uri = nil) ⇒ Object
88 89 90 91 |
# File 'lib/agent_client_protocol/error.rb', line 88 def resource_not_found(uri = nil) payload = uri.nil? ? nil : { "uri" => uri } new(code: ErrorCode::RESOURCE_NOT_FOUND, data: payload) end |
Instance Method Details
#to_h ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/agent_client_protocol/error.rb', line 41 def to_h error = { "code" => code, "message" => } error["data"] = data unless data.nil? error end |