Exception: Mailfloss::APIError
- Defined in:
- lib/mailfloss/errors.rb,
sig/mailfloss.rbs
Overview
Raised when the API responds with a non-2xx status.
The mailfloss API returns errors in the envelope:
{ "error": { "code": "...", "message": "...", "type": "...", "request_id": "..." } }
When the body is not JSON (or not in that envelope) the error degrades
gracefully: code becomes "unknown_error" and message falls back to
the raw body / a generic message.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
Returns the value of attribute code.
-
#request_id ⇒ String?
readonly
Returns the value of attribute request_id.
-
#status ⇒ Integer
readonly
Returns the value of attribute status.
-
#type ⇒ String?
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(status:, body: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(status:, body: nil) ⇒ APIError
Returns a new instance of APIError.
21 22 23 24 25 26 27 28 |
# File 'lib/mailfloss/errors.rb', line 21 def initialize(status:, body: nil) @status = status parsed = parse_error(body) @code = parsed[:code] @type = parsed[:type] @request_id = parsed[:request_id] super(parsed[:message]) end |
Instance Attribute Details
#code ⇒ String (readonly)
Returns the value of attribute code.
19 20 21 |
# File 'lib/mailfloss/errors.rb', line 19 def code @code end |
#request_id ⇒ String? (readonly)
Returns the value of attribute request_id.
19 20 21 |
# File 'lib/mailfloss/errors.rb', line 19 def request_id @request_id end |
#status ⇒ Integer (readonly)
Returns the value of attribute status.
19 20 21 |
# File 'lib/mailfloss/errors.rb', line 19 def status @status end |
#type ⇒ String? (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/mailfloss/errors.rb', line 19 def type @type end |