Exception: Locomotive::Coal::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Locomotive::Coal::Error
- Defined in:
- lib/locomotive/coal/error.rb
Overview
Take inspiration from this repository: github.com/vigeland/hooty
Direct Known Subclasses
FileTooBigError, InvalidResourceError, ServerSideError, TimeoutError, TooManyRequestsError, UnauthorizedError, UnknownResourceError
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
10 11 12 13 |
# File 'lib/locomotive/coal/error.rb', line 10 def initialize(response = nil) @response = response super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/locomotive/coal/error.rb', line 8 def response @response end |
Class Method Details
.from_response(response) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/locomotive/coal/error.rb', line 19 def self.from_response(response) status = response.status if klass = case status.to_i when 401 then Locomotive::Coal::UnauthorizedError when 404 then Locomotive::Coal::UnknownResourceError when 413 then Locomotive::Coal::FileTooBigError when 422 then Locomotive::Coal::InvalidResourceError when 429 then Locomotive::Coal::TooManyRequestsError when 500 then Locomotive::Coal::ServerSideError else Error end klass.new(response) end end |
Instance Method Details
#body ⇒ Object
15 16 17 |
# File 'lib/locomotive/coal/error.rb', line 15 def body @response.body || {} end |