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
Create an exception from the given response.
Instance Method Summary collapse
-
#build_message ⇒ Object
private
Private: Error message to be displayed.
-
#initialize(response = nil) ⇒ void
constructor
Initialize a new ReamazeAPI::Error instance.
Constructor Details
#initialize(response = nil) ⇒ void
Initialize a new ReamazeAPI::Error instance.
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
Create an exception from the given response.
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 |
Instance Method Details
#build_message ⇒ Object (private)
Private: Error message to be displayed.
45 46 47 48 49 50 51 52 53 |
# File 'lib/reamaze_api/error.rb', line 45 def return if @response.nil? = "#{@response[:method].to_s.upcase} " << "#{@response[:url]}: " << "#{@response[:status]}" << "\n\nBODY: #{@response[:body].inspect}" if @response[:body] end |