Exception: Mailkube::APIError
- Defined in:
- lib/mailkube/errors.rb,
sig/mailkube/errors.rbs
Overview
Raised for any non-2xx response, carrying the API's error envelope.
Rescue a subclass to branch on the category, and read the attributes for the detail. The
envelope's name stays a plain string, so a value this release has never heard of is
reported verbatim rather than coerced.
Direct Known Subclasses
AuthenticationError, BadRequestError, ConflictError, InvalidRequestError, NotFoundError, RateLimitError, ServerError
Instance Attribute Summary collapse
-
#body ⇒ Hash
readonly
The decoded response body, or an empty hash.
-
#error_name ⇒ String
readonly
The machine-readable name from the envelope, e.g.
-
#request_id ⇒ String?
readonly
The server's request id, to quote to support.
-
#retry_after ⇒ Integer?
readonly
The Retry-After header in seconds, when the server sent one.
-
#status_code ⇒ Integer
readonly
The HTTP status code.
Instance Method Summary collapse
-
#initialize(message = nil, error_name: "", status_code: 0, body: {}, retry_after: nil, request_id: nil) ⇒ APIError
constructor
There is deliberately one base constructor taking the whole envelope, and no subclass overrides it.
Constructor Details
#initialize(message = nil, error_name: "", status_code: 0, body: {}, retry_after: nil, request_id: nil) ⇒ APIError
There is deliberately one base constructor taking the whole envelope, and no subclass overrides it. Eight subclasses each repeating an argument list is how a duplication gate starts failing and how two categories start reporting different fields.
42 43 44 45 46 47 48 49 |
# File 'lib/mailkube/errors.rb', line 42 def initialize( = nil, error_name: "", status_code: 0, body: {}, retry_after: nil, request_id: nil) super( || (error_name.empty? ? "HTTP #{status_code}" : error_name)) @error_name = error_name @status_code = status_code @body = body @retry_after = retry_after @request_id = request_id end |
Instance Attribute Details
#body ⇒ Hash (readonly)
Returns the decoded response body, or an empty hash.
33 34 35 |
# File 'lib/mailkube/errors.rb', line 33 def body @body end |
#error_name ⇒ String (readonly)
Returns the machine-readable name from the envelope, e.g. quota_exceeded.
29 30 31 |
# File 'lib/mailkube/errors.rb', line 29 def error_name @error_name end |
#request_id ⇒ String? (readonly)
Returns the server's request id, to quote to support.
37 38 39 |
# File 'lib/mailkube/errors.rb', line 37 def request_id @request_id end |
#retry_after ⇒ Integer? (readonly)
Returns the Retry-After header in seconds, when the server sent one.
35 36 37 |
# File 'lib/mailkube/errors.rb', line 35 def retry_after @retry_after end |
#status_code ⇒ Integer (readonly)
Returns the HTTP status code.
31 32 33 |
# File 'lib/mailkube/errors.rb', line 31 def status_code @status_code end |