Module: Jirafe::ResponseParser::ClassMethods

Defined in:
lib/jirafe/response_parser.rb

Instance Method Summary collapse

Instance Method Details

#check_response_for_exception(response) ⇒ Object

Raises:

  • (exception)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jirafe/response_parser.rb', line 8

def check_response_for_exception(response)
  return if (200..399).include?(response.code) # Allow any 2xx or 3xx
  exception = case response.code.to_i
              when 400 # NOTE: Being thrown for what should be 422's
                Jirafe::Error::BadRequest
              when 401
                Jirafe::Error::Unauthorized
              when 403
                Jirafe::Error::Forbidden
              when 404
                Jirafe::Error::ResourceNotFound
              when 405
                Jirafe::Error::NotAllowed
              when 500
                Jirafe::Error::ServerError
              else
                Jirafe::Error::UnknownError
              end
  raise exception.new(response)
end