Exception: DilisensePepClient::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/dilisense_pep_client/errors.rb

Overview

Raised when the API returns an error response Contains HTTP status code, response body, and headers for debugging

Examples:

Handling API errors

begin
  results = client.check_individual(names: "Test")
rescue DilisensePepClient::APIError => e
  puts "API error: #{e.message}"
  puts "Status: #{e.status}"
  puts "Retryable? #{e.retryable?}"
end

Direct Known Subclasses

AuthenticationError, RateLimitError

Instance Attribute Summary collapse

Attributes inherited from Error

#context, #error_code, #request_id, #timestamp

Instance Method Summary collapse

Methods inherited from Error

#security_event?, #to_h

Constructor Details

#initialize(message, status: nil, body: nil, headers: {}, **options) ⇒ APIError

Returns a new instance of APIError.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/dilisense_pep_client/errors.rb', line 113

def initialize(message, status: nil, body: nil, headers: {}, **options)
  @status = status
  @body = sanitize_body(body)
  @headers = sanitize_headers(headers)
  
  context = {
    status: status,
    response_size: body&.to_s&.length,
    endpoint: options[:endpoint]
  }.merge(options.fetch(:context, {}))
  
  error_code = determine_error_code(status)
  
  super(message, error_code: error_code, context: context, **options)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



111
112
113
# File 'lib/dilisense_pep_client/errors.rb', line 111

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



111
112
113
# File 'lib/dilisense_pep_client/errors.rb', line 111

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



111
112
113
# File 'lib/dilisense_pep_client/errors.rb', line 111

def status
  @status
end

Instance Method Details

#client_error?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/dilisense_pep_client/errors.rb', line 137

def client_error?
  status.to_i.between?(400, 499)
end

#retryable?Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
# File 'lib/dilisense_pep_client/errors.rb', line 129

def retryable?
  case status
  when 429, 502, 503, 504 then true
  when 500..599 then true
  else false
  end
end

#server_error?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/dilisense_pep_client/errors.rb', line 141

def server_error?
  status.to_i.between?(500, 599)
end