Exception: Cased::HTTP::Error
- Defined in:
- lib/cased/http/error.rb
Constant Summary collapse
- RedirectionError =
3xx
Class.new(self)
- ClientError =
4xx
Class.new(self)
- BadRequest =
400
Class.new(ClientError)
Class.new(ClientError)
- Forbidden =
403
Class.new(ClientError)
- NotFound =
404
Class.new(ClientError)
- NotAcceptable =
406
Class.new(ClientError)
- RequestTimeout =
408
Class.new(ClientError)
- Conflict =
409
Class.new(ClientError)
- UnprocessableEntity =
422
Class.new(ClientError)
- TooManyRequests =
429
Class.new(ClientError)
- ServerError =
5xx
Class.new(self)
- InternalServerError =
500
Class.new(ServerError)
- BadGateway =
502
Class.new(ServerError)
Class.new(ServerError)
- GatewayTimeout =
504
Class.new(ServerError)
- ERRORS =
{ 400 => BadRequest, 401 => Unauthorized, 403 => Forbidden, 404 => NotFound, 406 => NotAcceptable, 408 => RequestTimeout, 422 => UnprocessableEntity, 429 => TooManyRequests, 500 => InternalServerError, 502 => BadGateway, 503 => ServiceUnavailable, 504 => GatewayTimeout, }.freeze
Constants inherited from Error
Error::MissingIdentifier, Error::SystemActorMissing
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json = {}, code = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(json = {}, code = nil) ⇒ Error
Returns a new instance of Error.
11 12 13 14 15 |
# File 'lib/cased/http/error.rb', line 11 def initialize(json = {}, code = nil) @json = json @code = code super(JSON.dump(@json)) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/cased/http/error.rb', line 9 def code @code end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
9 10 11 |
# File 'lib/cased/http/error.rb', line 9 def json @json end |
Class Method Details
.class_from_response(response) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cased/http/error.rb', line 21 def self.class_from_response(response) klass = ERRORS[response.status] if klass klass elsif (300...400).cover?(response.status) RedirectionError elsif (400...500).cover?(response.status) ClientError elsif (500...600).cover?(response.status) ServerError else self end end |
.from_response(response) ⇒ Object
17 18 19 |
# File 'lib/cased/http/error.rb', line 17 def self.from_response(response) new(response.body, response.status) end |