Class: HornOfPlenty::Adapters::Github::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/horn_of_plenty/adapters/github/error.rb

Constant Summary collapse

STATUS_CODE_ERROR_MAPPING =

rubocop:disable Metrics/LineLength

{
  400 => ['BadRequest',            'There was a general issue with your request.'],
  401 => ['AuthenticationFailure', 'There was a problem with the credentials you provided.'],
  403 => ['Forbidden',             'You are not authorized to access this resource.'],
  404 => ['NotFound',              'The resource you requested cannot be found.'],
  422 => ['UnprocessableEntity',   'We could not process your request.'],
  500 => ['ServerError',           'Something went wrong on the server.'],
}.freeze

Class Method Summary collapse

Class Method Details

.lookup(http_status_code, message = nil) ⇒ Object

rubocop:enable Metrics/LineLength



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/horn_of_plenty/adapters/github/error.rb', line 20

def self.lookup(http_status_code, message = nil)
  error_data = STATUS_CODE_ERROR_MAPPING[http_status_code]

  fail StandardError, "Unknown Status Code: #{http_status_code}" unless error_data

  error_namespace  = 'HornOfPlenty::Adapters::Github::Errors'
  error_class      = HornOfPlenty::CoreExt::String.constantize(
                       "#{error_namespace}::#{error_data[0]}",
  )

  error_class.new("#{error_data[1]}\n#{message}")
end