class CassetteRack::Response::Error

Attributes

response[R]

Public Class Methods

new(response) click to toggle source
Calls superclass method
# 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
status(env) click to toggle source
# 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

Public Instance Methods

response_body() click to toggle source
# File lib/cassette-rack/response/raise_error.rb, line 59
def response_body
  response[:body]
end
response_status() click to toggle source
# File lib/cassette-rack/response/raise_error.rb, line 55
def response_status
  response[:status]
end