Class: SimpleConnect::Responses::ErrorResponse

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#messageObject (readonly)

Returns the value of attribute message.



15
16
17
# File 'lib/simple_connect/responses/error_response.rb', line 15

def message
  @message
end

Instance Method Details

#to_hObject



22
23
24
# File 'lib/simple_connect/responses/error_response.rb', line 22

def to_h
  @json.dup
end