Exception: HermesAgent::Client::APIError
- Defined in:
- lib/hermes_agent/client/errors.rb
Overview
Raised when the server returns a non-2xx HTTP response.
The concrete class reflects the HTTP status: BadRequestError, AuthenticationError, PermissionError, NotFoundError, RateLimitError, or ServerError. A bare APIError is raised for any status that maps to none of those.
Error payloads
The server uses three distinct error formats, all of which the client
handles when building the error. Application-level errors (authentication,
body validation, missing resources on the /v1 surface) return an
OpenAI-style JSON body of the form {"error": {"message", "type",
"param"?, "code"?}}, and #error exposes that inner hash. The jobs
surface (/api/jobs) instead returns a flat {"error": "<message>"}
for its business errors (400/404/500); the message is still surfaced
on the exception message, but #error is nil (there is no inner hash).
Router-level
errors (an unrouted path, a wrong method) return a bare text body such as
"404: Not Found"; for those too #error is nil and only #body is
meaningful.
Even within the JSON family the field set is inconsistent — message and
type are always present, but param and code may be null or absent —
so treat #error entries as best-effort. Do not switch on type/code
to classify a failure (the server returns type: "invalid_request_error"
even for 401s); branch on the HTTP #status or the error subclass.
Direct Known Subclasses
AuthenticationError, BadRequestError, NotFoundError, PermissionError, RateLimitError, ServerError
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The raw response body.
-
#error ⇒ Hash?
readonly
The structured error payload (the inner
errorobject), ornilwhen the server returned a non-JSON body. -
#headers ⇒ Hash{String=>String}
readonly
The response headers, keyed by downcased name (the same normalized shape the success path exposes, so e.g.
headers["retry-after"]works regardless of the casing the server sent). -
#status ⇒ Integer
readonly
The HTTP status code of the error response.
Instance Attribute Details
#body ⇒ String (readonly)
The raw response body.
162 163 164 |
# File 'lib/hermes_agent/client/errors.rb', line 162 def body @body end |
#error ⇒ Hash? (readonly)
The structured error payload (the inner error object), or nil when
the server returned a non-JSON body. Field set is best-effort: expect
message and type, but param and code may be missing.
178 179 180 |
# File 'lib/hermes_agent/client/errors.rb', line 178 def error @error end |
#headers ⇒ Hash{String=>String} (readonly)
The response headers, keyed by downcased name (the same normalized
shape the success path exposes, so e.g. headers["retry-after"] works
regardless of the casing the server sent).
170 171 172 |
# File 'lib/hermes_agent/client/errors.rb', line 170 def headers @headers end |
#status ⇒ Integer (readonly)
The HTTP status code of the error response.
156 157 158 |
# File 'lib/hermes_agent/client/errors.rb', line 156 def status @status end |