module GOVUK::Client::Errors

Public Class Methods

create_for(restclient_exception) click to toggle source

Map rest-client exceptions onto our own exception hierarchy in order to insulate users from the details of the HTTP library we're using.

@api private

# File lib/govuk/client/errors.rb, line 13
def self.create_for(restclient_exception)
  if restclient_exception.http_code
    case restclient_exception.http_code
    when 409
      Conflict.new(restclient_exception)
    when 422
      UnprocessableEntity.new(restclient_exception)
    else
      HTTPError.new(restclient_exception)
    end
  else
    case restclient_exception
    when RestClient::RequestTimeout
      Timeout.new(restclient_exception.message)
    else
      BaseError.new(restclient_exception.message)
    end
  end
end