Exception: ApiAdaptor::HTTPErrorResponse

Inherits:
BaseError
  • Object
show all
Defined in:
lib/api_adaptor/exceptions.rb

Overview

Base class for all HTTP 4xx and 5xx error responses

Provides access to the HTTP status code, error details, and response body.

Examples:

Handling HTTP errors

begin
  client.get_json(url)
rescue ApiAdaptor::HTTPNotFound => e
  puts "Resource not found: #{e.code}"
rescue ApiAdaptor::HTTPServerError => e
  puts "Server error: #{e.code} - #{e.error_details}"
end

Direct Known Subclasses

HTTPClientError, HTTPServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message = nil, error_details = nil, http_body = nil) ⇒ HTTPErrorResponse

Initializes a new HTTP error response

Parameters:

  • code (Integer)

    HTTP status code

  • message (String, nil) (defaults to: nil)

    Error message

  • error_details (Hash, nil) (defaults to: nil)

    Parsed error details from JSON body

  • http_body (String, nil) (defaults to: nil)

    Raw HTTP response body



53
54
55
56
57
58
# File 'lib/api_adaptor/exceptions.rb', line 53

def initialize(code, message = nil, error_details = nil, http_body = nil)
  super(message)
  @code = code
  @error_details = error_details
  @http_body = http_body
end

Instance Attribute Details

#codeInteger, ...

Returns:

  • (Integer)

    HTTP status code

  • (Hash, nil)

    Parsed error details from response body

  • (String, nil)

    Raw HTTP response body



45
46
47
# File 'lib/api_adaptor/exceptions.rb', line 45

def code
  @code
end

#error_detailsInteger, ...

Returns:

  • (Integer)

    HTTP status code

  • (Hash, nil)

    Parsed error details from response body

  • (String, nil)

    Raw HTTP response body



45
46
47
# File 'lib/api_adaptor/exceptions.rb', line 45

def error_details
  @error_details
end

#http_bodyInteger, ...

Returns:

  • (Integer)

    HTTP status code

  • (Hash, nil)

    Parsed error details from response body

  • (String, nil)

    Raw HTTP response body



45
46
47
# File 'lib/api_adaptor/exceptions.rb', line 45

def http_body
  @http_body
end