Exception: Notisend::ApiError
- Defined in:
- lib/notisend/errors.rb
Overview
Non-2xx API response. Body format: "errors":[{"code":..,"detail":"."errors":[{"code":..,"detail":".."]}
Direct Known Subclasses
BadRequest, Forbidden, NotFound, PreconditionFailed, ServerError, TooManyRequests, Unauthorized, UnprocessableEntity
Constant Summary collapse
- STATUS_MAP =
{ 400 => 'Notisend::BadRequest', 401 => 'Notisend::Unauthorized', 403 => 'Notisend::Forbidden', 404 => 'Notisend::NotFound', 412 => 'Notisend::PreconditionFailed', 422 => 'Notisend::UnprocessableEntity', 429 => 'Notisend::TooManyRequests' }.freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #detail ⇒ Object
-
#initialize(status:, body:) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(status:, body:) ⇒ ApiError
Returns a new instance of ApiError.
37 38 39 40 41 |
# File 'lib/notisend/errors.rb', line 37 def initialize(status:, body:) @status = status @errors = parse_errors(body) super(detail || "Notisend API error (status #{status})") end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
30 31 32 |
# File 'lib/notisend/errors.rb', line 30 def errors @errors end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
30 31 32 |
# File 'lib/notisend/errors.rb', line 30 def status @status end |
Class Method Details
.for(status:, body:) ⇒ Object
32 33 34 35 |
# File 'lib/notisend/errors.rb', line 32 def self.for(status:, body:) klass_name = STATUS_MAP[status] || ((500..599).cover?(status) ? 'Notisend::ServerError' : name) Object.const_get(klass_name).new(status: status, body: body) end |
Instance Method Details
#detail ⇒ Object
43 44 45 |
# File 'lib/notisend/errors.rb', line 43 def detail errors.first&.fetch('detail', nil) end |