Exception: Billrb::ApiError
- Defined in:
- lib/billrb/errors.rb
Overview
Raised when the API responds with a non-2xx status. Subclasses map common statuses; ‘status` and `body` carry the raw response for callers that need the BILL error code or details.
Direct Known Subclasses
AuthenticationError, BadRequestError, ForbiddenError, NotFoundError, RateLimitError, ServerError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, status: nil, body: nil) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(message, status: nil, body: nil) ⇒ ApiError
Returns a new instance of ApiError.
19 20 21 22 23 |
# File 'lib/billrb/errors.rb', line 19 def initialize(, status: nil, body: nil) super() @status = status @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
17 18 19 |
# File 'lib/billrb/errors.rb', line 17 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
17 18 19 |
# File 'lib/billrb/errors.rb', line 17 def status @status end |
Class Method Details
.from_response(status:, body:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/billrb/errors.rb', line 25 def self.from_response(status:, body:) klass = case status when 400 then BadRequestError when 401 then AuthenticationError when 403 then ForbiddenError when 404 then NotFoundError when 429 then RateLimitError when 500..599 then ServerError else ApiError end klass.new((body) || "HTTP #{status}", status: status, body: body) end |