Module: Walinko::ErrorMapping

Defined in:
lib/walinko/errors.rb

Overview

Internal: maps an HTTP status + server ‘error_code` to one of the typed exception classes above. Public so users can introspect the mapping in tests if they want.

Constant Summary collapse

BY_HTTP_STATUS =
{
  400 => BadRequestError,
  401 => AuthenticationError,
  403 => ForbiddenError,
  404 => NotFoundError,
  409 => ConflictError,
  422 => ValidationError,
  429 => RateLimitError,
  504 => TimeoutError
}.freeze
BY_ERROR_CODE =
{
  'tenant_suspended' => TenantSuspendedError,
  'quota_exceeded' => QuotaExceededError,
  'device_disconnected' => DeviceDisconnectedError,
  'idempotency_conflict' => IdempotencyConflictError
}.freeze

Class Method Summary collapse

Class Method Details

.for(http_status:, error_code: nil) ⇒ Class<ApiError>

Returns:



135
136
137
138
139
# File 'lib/walinko/errors.rb', line 135

def self.for(http_status:, error_code: nil)
  BY_ERROR_CODE[error_code.to_s] ||
    BY_HTTP_STATUS[http_status] ||
    (http_status.between?(500, 599) ? ServerError : ApiError)
end