Exception: VistarClient::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/vistar_client/error.rb

Overview

Raised when the API returns an error response (HTTP 4xx/5xx).

This error includes the HTTP status code and response body for debugging.

Examples:

Handle API errors

begin
  client.request_ad(params)
rescue VistarClient::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
  puts "Response body: #{e.response_body}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status_code: nil, response_body: nil) ⇒ APIError

Initialize an APIError with optional HTTP details.

Parameters:

  • message (String)

    Error message

  • status_code (Integer, nil) (defaults to: nil)

    HTTP status code

  • response_body (Hash, String, nil) (defaults to: nil)

    Response body



58
59
60
61
62
# File 'lib/vistar_client/error.rb', line 58

def initialize(message, status_code: nil, response_body: nil)
  super(message)
  @status_code = status_code
  @response_body = response_body
end

Instance Attribute Details

#response_bodyHash, ... (readonly)

Returns Response body from the error response.

Returns:

  • (Hash, String, nil)

    Response body from the error response



50
51
52
# File 'lib/vistar_client/error.rb', line 50

def response_body
  @response_body
end

#status_codeInteger? (readonly)

Returns HTTP status code from the error response.

Returns:

  • (Integer, nil)

    HTTP status code from the error response



47
48
49
# File 'lib/vistar_client/error.rb', line 47

def status_code
  @status_code
end