Class: QualtricsAPI::RequestErrorHandler

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/qualtrics_api/request_error_handler.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/qualtrics_api/request_error_handler.rb', line 3

def on_complete(env)
  case env[:status]
  when 404
    raise NotFoundError, "Not Found"
  when 400
    raise BadRequestError, error_message(JSON.parse(env[:body]))
  when 401
    raise UnauthorizedError, error_message(JSON.parse(env[:body]))
  when 500
    raise InternalServerError, error_message(JSON.parse(env[:body]))
  end
end