Exception: DilisensePepClient::APIError
- 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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Attributes inherited from Error
#context, #error_code, #request_id, #timestamp
Instance Method Summary collapse
- #client_error? ⇒ Boolean
-
#initialize(message, status: nil, body: nil, headers: {}, **options) ⇒ APIError
constructor
A new instance of APIError.
- #retryable? ⇒ Boolean
- #server_error? ⇒ Boolean
Methods inherited from Error
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(, status: nil, body: nil, headers: {}, **) @status = status @body = sanitize_body(body) @headers = sanitize_headers(headers) context = { status: status, response_size: body&.to_s&.length, endpoint: [:endpoint] }.merge(.fetch(:context, {})) error_code = determine_error_code(status) super(, error_code: error_code, context: context, **) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
111 112 113 |
# File 'lib/dilisense_pep_client/errors.rb', line 111 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
111 112 113 |
# File 'lib/dilisense_pep_client/errors.rb', line 111 def headers @headers end |
#status ⇒ Object (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
137 138 139 |
# File 'lib/dilisense_pep_client/errors.rb', line 137 def client_error? status.to_i.between?(400, 499) end |
#retryable? ⇒ 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
141 142 143 |
# File 'lib/dilisense_pep_client/errors.rb', line 141 def server_error? status.to_i.between?(500, 599) end |