Exception: CassetteRack::Response::Error
- Inherits:
-
StandardError
- Object
- StandardError
- CassetteRack::Response::Error
- Defined in:
- lib/cassette-rack/response/raise_error.rb
Direct Known Subclasses
BadGateway, BadRequest, Conflict, Forbidden, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, NotImplemented, ServiceUnavailable, Unauthorized, UnprocessableEntity
Defined Under Namespace
Classes: BadGateway, BadRequest, Conflict, Forbidden, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, NotImplemented, ServiceUnavailable, Unauthorized, UnprocessableEntity
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ Error
constructor
A new instance of Error.
- #response_body ⇒ Object
- #response_status ⇒ Object
Constructor Details
#initialize(response) ⇒ Error
Returns a new instance of Error.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cassette-rack/response/raise_error.rb', line 39 def initialize(response) @response = response str = response[:body] if response.request_headers['accept'] == 'application/json' begin body = JSON.parse(response[:body]) str = body['message'] if body.key?('message') str = body['error_message'] if body.key?('error_message') rescue end end super(str) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
14 15 16 |
# File 'lib/cassette-rack/response/raise_error.rb', line 14 def response @response end |
Class Method Details
.status(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cassette-rack/response/raise_error.rb', line 16 def self.status(env) if klass = case env[:status] when 400 then Response::Error::BadRequest when 401 then Response::Error::Unauthorized when 403 then Response::Error::Forbidden when 404 then Response::Error::NotFound when 405 then Response::Error::MethodNotAllowed when 406 then Response::Error::NotAcceptable when 409 then Response::Error::Conflict when 415 then Response::Error::UnsupportedMediaType when 422 then Response::Error::UnprocessableEntity when 400..499 then Response::Error::ClientError when 500 then Response::Error::InternalServerError when 501 then Response::Error::NotImplemented when 502 then Response::Error::BadGateway when 503 then Response::Error::ServiceUnavailable when 500..599 then Response::Error::ServerError end klass.new(env) end end |
Instance Method Details
#response_body ⇒ Object
59 60 61 |
# File 'lib/cassette-rack/response/raise_error.rb', line 59 def response_body response[:body] end |
#response_status ⇒ Object
55 56 57 |
# File 'lib/cassette-rack/response/raise_error.rb', line 55 def response_status response[:status] end |