Exception: Breacan::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Breacan::Error
- Defined in:
- lib/breacan/error.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #errors ⇒ Object
-
#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/breacan/error.rb', line 29 def initialize(response = nil) @response = response super() end |
Class Method Details
.from_body(response, body) ⇒ Object
25 26 27 |
# File 'lib/breacan/error.rb', line 25 def self.from_body(response, body) Breacan::BadRequest.new(response) unless body[:ok] end |
.from_response(response) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/breacan/error.rb', line 3 def self.from_response(response) status = response[:status].to_i if klass = case status when 400 then Breacan::BadRequest when 401 then Breacan::Unauthorized when 403 then Breacan::Forbidden when 404 then Breacan::NotFound when 406 then Breacan::NotAcceptable when 409 then Breacan::Conflict when 415 then Breacan::UnsupportedMediaType when 422 then Breacan::UnprocessableEntity when 400..499 then Breacan::ClientError when 500 then Breacan::InternalServerError when 501 then Breacan::NotImplemented when 502 then Breacan::BadGateway when 503 then Breacan::ServiceUnavailable when 500..599 then Breacan::ServerError end klass.new(response) end end |
Instance Method Details
#errors ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/breacan/error.rb', line 34 def errors if data && data.is_a?(Hash) data[:errors] || [] else [] end end |