Module: Splunker::Errors

Defined in:
lib/splunker/errors.rb

Defined Under Namespace

Classes: AuthenticationFailureError, ClientError, ConfigurationError, FeatureDisabledError, InternalServerError, InvalidOperationError, MethodNotAllowedError, ObjectDoesNotExistError, PermissionDeniedError

Constant Summary collapse

STATUS_CODE_TO_ERROR_MAP =
{
  401 => AuthenticationFailureError,
  402 => FeatureDisabledError,
  403 => PermissionDeniedError,
  404 => ObjectDoesNotExistError,
  405 => MethodNotAllowedError,
  409 => InvalidOperationError,
  500 => InternalServerError 
}

Class Method Summary collapse

Class Method Details

.raise_error_for_status!(http_status, body) ⇒ Object

Parameters:

  • http_status => The integer representing the HTTP status

  • body => The response body. Will be passed to the

    error instance when raised, for additional
    information.
    

Returns nil if no exception will be raised. Raises an error mapped to http_status in STATUS_CODE_TO_ERROR_MAP, or ClientError if status is not 2xx but no mapped error exists.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/splunker/errors.rb', line 34

def self.raise_error_for_status!(http_status, body)
  return nil if (200..299).include?(http_status)

  if STATUS_CODE_TO_ERROR_MAP[http_status]
    raise STATUS_CODE_TO_ERROR_MAP[http_status], body
  else
    raise ClientError, body
  end

  nil
end