Module: Gitlab::Error

Defined in:
lib/gitlab/error.rb

Defined Under Namespace

Classes: BadGateway, BadRequest, Conflict, ConnectionTimedOut, Error, Forbidden, InternalServerError, MethodNotAllowed, MissingCredentials, NotAcceptable, NotFound, Parsing, ResponseError, ServiceUnavailable, TooManyRequests, Unauthorized, Unprocessable

Constant Summary collapse

STATUS_MAPPINGS =

HTTP status codes mapped to error classes.

{
  400 => BadRequest,
  401 => Unauthorized,
  403 => Forbidden,
  404 => NotFound,
  405 => MethodNotAllowed,
  406 => NotAcceptable,
  409 => Conflict,
  422 => Unprocessable,
  429 => TooManyRequests,
  500 => InternalServerError,
  502 => BadGateway,
  503 => ServiceUnavailable,
  522 => ConnectionTimedOut
}.freeze

Class Method Summary collapse

Class Method Details

.klass(response) ⇒ Class<Error::ResponseError>?

Returns error class that should be raised for this response. Returns nil if the response status code is not 4xx or 5xx.

Parameters:

  • response (HTTParty::Response)

    The response object.

Returns:



163
164
165
166
167
168
# File 'lib/gitlab/error.rb', line 163

def self.klass(response)
  error_klass = STATUS_MAPPINGS[response.code]
  return error_klass if error_klass

  ResponseError if response.server_error? || response.client_error?
end