errors.go (package eai)
Source: sdks/go/errors.go. Back to the Go SDK reference index.
This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.
Class APIError
APIError is the error envelope {"error": {code, message, message_i18n, details, request_id}} returned with HTTP 4xx/5xx, plus network errors (Code "network_error", Status 0).
Fields:
| Name | Type | Required | Description |
|---|---|---|---|
Status | int | yes | HTTP status of the response, 0 for a network error. |
Code | string | yes | Machine code of the error (policy_denied, not_found...); derived from the HTTP status when the body has none, network_error for a network failure. |
Message | string | yes | Message in the client language: message_i18n first, then the SDK catalog or the server message. |
MessageI18n | map[string]string | yes | The message_i18n map of the envelope, message per language code. |
Details | map[string]any | yes | The details object of the envelope with secrets redacted, never nil. |
RequestID | string | yes | Request identifier from the envelope, or from the response header when the body has none. |
RetryAfter | time.Duration | yes | RetryAfter is set when the server sent Retry-After (HasRetryAfter true). |
HasRetryAfter | bool | yes | true when the server sent a Retry-After header, then RetryAfter holds its value. |
APIError.ApprovalID
ApprovalID() string
ApprovalID returns details.approval_id of an approval_required error.
This element takes no parameter.
Returns: string. The approval_id string of Details, empty when absent.
APIError.Error
Error() string
Error formats the error as eai: <code> (HTTP <status>): <message>, without the HTTP part for a network error.
This element takes no parameter.
Returns: string. The error text with code, status and message.
APIError.Is
Is(target error) bool
Is matches the Err* sentinels by machine code (errors.Is(err, eai.ErrPolicyDenied)).
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
target | error | yes | Error to compare with, matched only when it is one of the Err* sentinels. |
Returns: bool. true when the code matches the sentinel; ErrQuotaExceeded, ErrNotFound and ErrAuth also match related codes and HTTP statuses.
APIError.Unwrap
Unwrap() error
Unwrap returns the underlying network error, if any.
This element takes no parameter.
Returns: error. Error of the call (a typed error of the SDK), nil on success.
Raises: error.
Functions
AsAPIError
AsAPIError(err error) (*APIError, bool)
AsAPIError extracts an *APIError.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error returned by the SDK, possibly wrapped. |
Returns: (*APIError, bool). The *APIError found with errors.As and true, or nil and false.
IsPolicyDenied
IsPolicyDenied(err error) bool
IsPolicyDenied reports a policy_denied error.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true when err matches ErrPolicyDenied.
IsQuotaExceeded
IsQuotaExceeded(err error) bool
IsQuotaExceeded reports quota_exceeded or budget_exceeded.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true for the quota_exceeded and budget_exceeded codes.
IsEffortNotSupported
IsEffortNotSupported(err error) bool
IsEffortNotSupported reports effort_not_supported.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true when err matches ErrEffortNotSupported.
IsContextOverflow
IsContextOverflow(err error) bool
IsContextOverflow reports context_overflow.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true when err matches ErrContextOverflow.
IsApprovalRequired
IsApprovalRequired(err error) bool
IsApprovalRequired reports approval_required.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true when err matches ErrApprovalRequired.
IsNotFound
IsNotFound(err error) bool
IsNotFound reports not_found or HTTP 404.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true for the not_found code or an HTTP 404 status.
IsAuth
IsAuth(err error) bool
IsAuth reports HTTP 401/403 authentication or permission errors.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
err | error | yes | Error to test. |
Returns: bool. true for unauthenticated, forbidden, HTTP 401, or HTTP 403 other than policy_denied.