Skip to main content

errors.go (package eai)

Source: sdks/go/errors.go. Back to the Go SDK reference index.

note

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:

NameTypeRequiredDescription
StatusintyesHTTP status of the response, 0 for a network error.
CodestringyesMachine code of the error (policy_denied, not_found...); derived from the HTTP status when the body has none, network_error for a network failure.
MessagestringyesMessage in the client language: message_i18n first, then the SDK catalog or the server message.
MessageI18nmap[string]stringyesThe message_i18n map of the envelope, message per language code.
Detailsmap[string]anyyesThe details object of the envelope with secrets redacted, never nil.
RequestIDstringyesRequest identifier from the envelope, or from the response header when the body has none.
RetryAftertime.DurationyesRetryAfter is set when the server sent Retry-After (HasRetryAfter true).
HasRetryAfterboolyestrue 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)).

NameTypeDefaultRequiredDescription
targeterroryesError 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.

NameTypeDefaultRequiredDescription
errerroryesError 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.

NameTypeDefaultRequiredDescription
errerroryesError to test.

Returns: bool. true when err matches ErrPolicyDenied.

IsQuotaExceeded​

IsQuotaExceeded(err error) bool

IsQuotaExceeded reports quota_exceeded or budget_exceeded.

NameTypeDefaultRequiredDescription
errerroryesError to test.

Returns: bool. true for the quota_exceeded and budget_exceeded codes.

IsEffortNotSupported​

IsEffortNotSupported(err error) bool

IsEffortNotSupported reports effort_not_supported.

NameTypeDefaultRequiredDescription
errerroryesError to test.

Returns: bool. true when err matches ErrEffortNotSupported.

IsContextOverflow​

IsContextOverflow(err error) bool

IsContextOverflow reports context_overflow.

NameTypeDefaultRequiredDescription
errerroryesError to test.

Returns: bool. true when err matches ErrContextOverflow.

IsApprovalRequired​

IsApprovalRequired(err error) bool

IsApprovalRequired reports approval_required.

NameTypeDefaultRequiredDescription
errerroryesError to test.

Returns: bool. true when err matches ErrApprovalRequired.

IsNotFound​

IsNotFound(err error) bool

IsNotFound reports not_found or HTTP 404.

NameTypeDefaultRequiredDescription
errerroryesError 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.

NameTypeDefaultRequiredDescription
errerroryesError to test.

Returns: bool. true for unauthenticated, forbidden, HTTP 401, or HTTP 403 other than policy_denied.