Exception: Millionsend::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Millionsend::Error
- Defined in:
- lib/millionsend/error.rb
Overview
Base class for everything this SDK raises. Mirrors the API's wire error body { statusCode, name, message }; #status_code is nil for client-side and transport failures that never reached the API.
Direct Known Subclasses
ApplicationError, InvalidIdempotentRequestError, NotFoundError, RestrictedApiKeyError, SendingPausedError, ValidationError
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
-
.from_response(status, body) ⇒ Object
Build the right subclass from a non-2xx response, keyed on the stable
namediscriminant.
Instance Method Summary collapse
-
#initialize(message, status_code = nil, name = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(message, status_code = nil, name = nil) ⇒ Error
Returns a new instance of Error.
10 11 12 13 14 |
# File 'lib/millionsend/error.rb', line 10 def initialize(, status_code = nil, name = nil) super() @status_code = status_code @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/millionsend/error.rb', line 8 def name @name end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
8 9 10 |
# File 'lib/millionsend/error.rb', line 8 def status_code @status_code end |
Class Method Details
.from_response(status, body) ⇒ Object
Build the right subclass from a non-2xx response, keyed on the stable
name discriminant. Falls back to ApplicationError for unknown names or a
body that is not the canonical error shape.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/millionsend/error.rb', line 19 def self.from_response(status, body) if body.is_a?(Hash) name = body[:name].is_a?(String) ? body[:name] : "application_error" = body[:message].is_a?(String) ? body[:message] : "Request failed with status #{status}" code = body[:statusCode].is_a?(Integer) ? body[:statusCode] : status else name = "application_error" = "Request failed with status #{status}" code = status end (ERROR_TYPES[name] || ApplicationError).new(, code, name) end |