Exception: Bettery::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Bettery::Error
- Defined in:
- lib/bettery/error.rb
Overview
Custom error class for rescuing from all Betterplace errors
Direct Known Subclasses
Class Method Summary collapse
-
.from_response(response) ⇒ Bettery::Error
Returns the appropriate Bettery::Error sublcass based on status and response message.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
29 30 31 32 |
# File 'lib/bettery/error.rb', line 29 def initialize(response=nil) @response = response super() end |
Class Method Details
.from_response(response) ⇒ Bettery::Error
Returns the appropriate Bettery::Error sublcass based on status and response message
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bettery/error.rb', line 10 def self.from_response(response) status = response[:status].to_i body = response[:body].to_s headers = response[:response_headers] if klass = case status when 400 then Bettery::BadRequest when 403 then Bettery::Forbidden when 404 then Bettery::NotFound when 400..499 then Bettery::ClientError when 500 then Bettery::InternalServerError when 502 then Bettery::BadGateway when 503 then Bettery::ServiceUnavailable when 500..599 then Bettery::ServerError end klass.new(response) end end |