Class: MailchimpAPI::FailedRequestErrorBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mailchimp-api/failed_request_error_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal class for building failed request error instances

Constant Summary collapse

RESPONSE_ERROR_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Maps HTTP response classes to corresponding Mailchimp API error classes

Returns:

  • (Hash)

    Mapping of Net::HTTP response classes to MailchimpAPI::Error classes

{
  Net::HTTPBadRequest => Errors::BadRequest,                     # 400
  Net::HTTPUnauthorized => Errors::Unauthorized,                 # 401
  Net::HTTPForbidden => Errors::Forbidden,                       # 403
  Net::HTTPNotFound => Errors::NotFound,                         # 404
  Net::HTTPMethodNotAllowed => Errors::MethodNotAllowed,         # 405
  Net::HTTPRequestURITooLong => Errors::RequestURITooLong,       # 414
  Net::HTTPUnprocessableEntity => Errors::UnprocessableEntity,   # 422
  Net::HTTPUpgradeRequired => Errors::UpgradeRequired,           # 426
  Net::HTTPTooManyRequests => Errors::TooManyRequests,           # 429
  Net::HTTPServerError => Errors::ServerError                    # 5xx
}.freeze

Class Method Summary collapse

Class Method Details

.call(request:, response:) ⇒ Errors::FailedRequest

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new error instance based on the HTTP response

Parameters:

  • request (Request)

    The original request that failed

  • response (Response)

    The response containing the error

Returns:



29
30
31
32
33
34
35
# File 'lib/mailchimp-api/failed_request_error_builder.rb', line 29

def call(request:, response:)
  http_response = response.http_response
  error_message = "#{http_response.code} #{http_response.message}"
  error_class = find_error_class(http_response)

  error_class.new(error_message, response: response, request: request)
end