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, String
readonly
Response body parsed as Hash, or raw String for binary error responses (e.g., grey image bodies).
-
#headers ⇒ Hash
readonly
Response headers.
-
#params ⇒ Hash?
readonly
Additional error details from the response body.
-
#status ⇒ Integer?
readonly
HTTP status code.
Instance Method Summary collapse
-
#error_code ⇒ String?
Returns the error code for this error.
-
#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.
91 92 93 94 95 96 97 |
# File 'lib/reve_ai/errors.rb', line 91 def initialize( = nil, status: nil, body: nil, headers: nil) @status = status @body = body || {} @headers = headers || {} @params = @body.is_a?(Hash) ? @body[:params] : nil super() end |
Instance Attribute Details
#body ⇒ Hash, String (readonly)
Returns Response body parsed as Hash, or raw String for binary error responses (e.g., grey image bodies).
77 78 79 |
# File 'lib/reve_ai/errors.rb', line 77 def body @body end |
#headers ⇒ Hash (readonly)
Returns Response headers.
80 81 82 |
# File 'lib/reve_ai/errors.rb', line 80 def headers @headers end |
#params ⇒ Hash? (readonly)
Returns Additional error details from the response body.
83 84 85 |
# File 'lib/reve_ai/errors.rb', line 83 def params @params 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 for this error.
Read from the response body when present, falling back to the X-Reve-Error-Code header: with an image Accept header, the API answers errors with a small grey image body and no JSON error code.
115 116 117 118 119 |
# File 'lib/reve_ai/errors.rb', line 115 def error_code return body[:error_code] if body.is_a?(Hash) && body[:error_code] headers["x-reve-error-code"] end |
#request_id ⇒ String?
Returns the request ID from response headers.
Useful for debugging and support requests.
104 105 106 |
# File 'lib/reve_ai/errors.rb', line 104 def request_id headers["x-reve-request-id"] end |