Class: SimpleConnect::Responses::ErrorResponse
- Inherits:
-
Object
- Object
- SimpleConnect::Responses::ErrorResponse
- Defined in:
- lib/simple_connect/responses/error_response.rb
Overview
Wraps the JSON error body returned on 4xx / 5xx responses. Server error envelopes today are uniform (‘“…”` possibly with `false`). If the server grows richer error shapes later, this class can be extended in place without adding per-endpoint error subclasses.
Construction is defensive: a non-Hash argument, nil, or a Hash missing the “error” key all produce ‘message == “”` — never raises. Callers always have `result.error` (the short HTTP-level string) as a fallback.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(json) ⇒ ErrorResponse
constructor
A new instance of ErrorResponse.
- #to_h ⇒ Object
Constructor Details
#initialize(json) ⇒ ErrorResponse
Returns a new instance of ErrorResponse.
17 18 19 20 |
# File 'lib/simple_connect/responses/error_response.rb', line 17 def initialize(json) @json = json.is_a?(Hash) ? json : {} @message = @json["error"].to_s end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'lib/simple_connect/responses/error_response.rb', line 15 def @message end |
Instance Method Details
#to_h ⇒ Object
22 23 24 |
# File 'lib/simple_connect/responses/error_response.rb', line 22 def to_h @json.dup end |