Class: GroqRuby::ErrorMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/groq_ruby/error_mapper.rb

Overview

Maps an HTTP status code + parsed body to the matching APIStatusError subclass. Single-purpose: status in, exception instance out.

Constant Summary collapse

STATUS_CLASSES =
{
  400 => BadRequestError,
  401 => AuthenticationError,
  403 => PermissionDeniedError,
  404 => NotFoundError,
  409 => ConflictError,
  422 => UnprocessableEntityError,
  429 => RateLimitError
}.freeze

Class Method Summary collapse

Class Method Details

.call(status:, headers:, body:) ⇒ APIStatusError

Parameters:

  • status (Integer)

    HTTP status code

  • headers (Hash)

    response headers

  • body (Object, nil)

    decoded JSON body (Hash) or raw String

Returns:



19
20
21
22
23
# File 'lib/groq_ruby/error_mapper.rb', line 19

def self.call(status:, headers:, body:)
  klass = resolve_class(status)
  message = extract_message(body) || "Groq API returned status #{status}"
  klass.new(message, status: status, headers: headers, body: body)
end