Exception: Freshly::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Freshly::Error
- Defined in:
- lib/freshly/error.rb
Direct Known Subclasses
AccessDenied, AuthenticationFailed, BadGateway, BadRequest, ClientError, Conflict, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, NotImplemented, RateLimitExceeded, ServerError, ServiceUnavailable, UnsupportedMediaType
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #build_error_message ⇒ Object
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
32 33 34 35 |
# File 'lib/freshly/error.rb', line 32 def initialize(response=nil) @response = response super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/freshly/error.rb', line 3 def response @response end |
Class Method Details
.from_response(response) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/freshly/error.rb', line 5 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 Freshly::BadRequest when 401 then Freshly::AuthenticationFailed when 403 then Freshly::AccessDenied when 404 then Freshly::NotFound when 405 then Freshly::MethodNotAllowed when 406 then Freshly::NotAcceptable when 409 then Freshly::Conflict when 415 then Freshly::UnsupportedMediaType when 429 then Freshly::RateLimitExceeded when 400..499 then Freshly::ClientError when 500 then Freshly::InternalServerError when 501 then Freshly::NotImplemented when 502 then Freshly::BadGateway when 503 then Freshly::ServiceUnavailable when 500..599 then Freshly::ServerError end klass.new(response) end end |
Instance Method Details
#build_error_message ⇒ Object
37 38 39 |
# File 'lib/freshly/error.rb', line 37 def "something went wrong" end |