module Minfraud::ErrorHandler

ErrorHandler provides a method to raise exceptions on errors.

Constants

STATUS_CODES

@!visibility private

Public Class Methods

examine(response) click to toggle source

Return the response if the HTTP status code is 2xx. Otherwise raise an error.

@param response [Minfraud::HTTPService::Response]

@return [Minfraud::HTTPService::Response]

@raise [Minfraud::AuthorizationError] If there was an authentication

problem.

@raise [Minfraud::ClientError] If there was a critical problem with one

of your inputs.

@raise [Minfraud::ServerError] If the server reported an error of some

kind.
# File lib/minfraud/error_handler.rb, line 22
def examine(response)
  return response if response.status > 199 && response.status < 300

  raise(*STATUS_CODES.fetch(response.code, [ServerError, 'Server error']))
end