Exception: ReveAI::APIError
- Defined in:
- lib/reve_ai/errors.rb
Overview
Base class for API errors with HTTP status and response details.
All API-related exceptions inherit from this class and include HTTP status code, response body, and headers for debugging.
Direct Known Subclasses
BadRequestError, ForbiddenError, InsufficientCreditsError, NotFoundError, RateLimitError, ServerError, UnauthorizedError, UnprocessableEntityError
Instance Attribute Summary collapse
-
#body ⇒ Hash
readonly
Response body parsed as Hash.
-
#headers ⇒ Hash
readonly
Response headers.
-
#status ⇒ Integer?
readonly
HTTP status code.
Instance Method Summary collapse
-
#error_code ⇒ String?
Returns the error code from the response body.
-
#initialize(message = nil, status: nil, body: nil, headers: nil) ⇒ APIError
constructor
Creates a new API error instance.
-
#request_id ⇒ String?
Returns the request ID from response headers.
Constructor Details
#initialize(message = nil, status: nil, body: nil, headers: nil) ⇒ APIError
Creates a new API error instance.
87 88 89 90 91 92 |
# File 'lib/reve_ai/errors.rb', line 87 def initialize( = nil, status: nil, body: nil, headers: nil) @status = status @body = body || {} @headers = headers || {} super() end |
Instance Attribute Details
#body ⇒ Hash (readonly)
Returns Response body parsed as Hash.
76 77 78 |
# File 'lib/reve_ai/errors.rb', line 76 def body @body end |
#headers ⇒ Hash (readonly)
Returns Response headers.
79 80 81 |
# File 'lib/reve_ai/errors.rb', line 79 def headers @headers end |
#status ⇒ Integer? (readonly)
Returns HTTP status code.
73 74 75 |
# File 'lib/reve_ai/errors.rb', line 73 def status @status end |
Instance Method Details
#error_code ⇒ String?
Returns the error code from the response body.
106 107 108 |
# File 'lib/reve_ai/errors.rb', line 106 def error_code body[:error_code] end |
#request_id ⇒ String?
Returns the request ID from response headers.
Useful for debugging and support requests.
99 100 101 |
# File 'lib/reve_ai/errors.rb', line 99 def request_id headers["x-reve-request-id"] end |