Exception: ReamazeAPI::Error
- Inherits:
-
StandardError
- Object
- StandardError
- ReamazeAPI::Error
- Defined in:
- lib/reamaze_api/error.rb
Overview
Encapsulates HTTP errors that may be returned by the Reamaze API. All API errors inherit from this class.
Direct Known Subclasses
Class Method Summary collapse
-
.from_response(response) ⇒ Object
Public: Create an exception from the given response.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Error
constructor
Public: Initialize a new ReamazeAPI::Error instance.
Constructor Details
#initialize(response = nil) ⇒ Error
Public: Initialize a new ReamazeAPI::Error instance.
response - HTTP response (Faraday::Env)
Returns nothing.
35 36 37 38 |
# File 'lib/reamaze_api/error.rb', line 35 def initialize(response = nil) @response = response super() end |
Class Method Details
.from_response(response) ⇒ Object
Public: Create an exception from the given response.
response - HTTP response (Faraday::Env)
Returns a ReamazeAPI::Error or nil.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/reamaze_api/error.rb', line 10 def self.from_response(response) if klass = case response[:status].to_i when 403 ReamazeAPI::Forbidden when 404 ReamazeAPI::NotFound when 422 ReamazeAPI::UnprocessableEntity when 429 ReamazeAPI::TooManyRequests when 400..499 ReamazeAPI::ClientError when 500..599 ReamazeAPI::ServerError end klass.new(response) end end |