Exception: DatabasusRuby::APIError
- Defined in:
- lib/databasus_ruby/error.rb,
lib/databasus_ruby/error.rb,
sig/databasus_ruby.rbs
Overview
Raised when Databasus answers with a non-successful status code.
Direct Known Subclasses
AuthenticationError, BadRequestError, ConflictError, ForbiddenError, NotFoundError, RateLimitError, ServerError
Constant Summary collapse
- STATUS_ERRORS =
{ 400 => BadRequestError, 401 => AuthenticationError, 403 => ForbiddenError, 404 => NotFoundError, 409 => ConflictError, 429 => RateLimitError }.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status ⇒ Integer?
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .for_status(status) ⇒ singleton(APIError)
-
.from_response(response) ⇒ APIError
Maps a Faraday response onto the most specific error class available.
Instance Method Summary collapse
-
#initialize(message = nil, status: nil, body: nil, response: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(message = nil, status: nil, body: nil, response: nil) ⇒ APIError
Returns a new instance of APIError.
15 16 17 18 19 20 |
# File 'lib/databasus_ruby/error.rb', line 15 def initialize( = nil, status: nil, body: nil, response: nil) @status = status @body = body @response = response super( || "Databasus API returned #{status}") end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/databasus_ruby/error.rb', line 13 def body @body end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/databasus_ruby/error.rb', line 13 def response @response end |
#status ⇒ Integer? (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/databasus_ruby/error.rb', line 13 def status @status end |
Class Method Details
.for_status(status) ⇒ singleton(APIError)
28 29 30 31 32 |
# File 'lib/databasus_ruby/error.rb', line 28 def self.for_status(status) return ServerError if (500..599).cover?(status) STATUS_ERRORS.fetch(status, APIError) end |
.from_response(response) ⇒ APIError
Maps a Faraday response onto the most specific error class available.
23 24 25 26 |
# File 'lib/databasus_ruby/error.rb', line 23 def self.from_response(response) klass = for_status(response.status) klass.new((response.body), status: response.status, body: response.body, response: response) end |