Documentation
¶
Overview ¶
Package errors provides types and utilities for API errors.
Index ¶
- func IsAPIError(err error) bool
- func IsAPIErrorAlreadyExistsStatus(err error) bool
- func IsAPIErrorCancelledStatus(err error) bool
- func IsAPIErrorDeadlineExceededStatus(err error) bool
- func IsAPIErrorFailedPreconditionStatus(err error) bool
- func IsAPIErrorIdempotencyKeyAlreadyUsedStatus(err error) bool
- func IsAPIErrorInternalStatus(err error) bool
- func IsAPIErrorInvalidArgumentStatus(err error) bool
- func IsAPIErrorInvalidEtagKeyStatus(err error) bool
- func IsAPIErrorMethodNotAllowedStatus(err error) bool
- func IsAPIErrorNotFoundStatus(err error) bool
- func IsAPIErrorPermissionDeniedStatus(err error) bool
- func IsAPIErrorQuotaExceededStatus(err error) bool
- func IsAPIErrorTooManyRequestsStatus(err error) bool
- func IsAPIErrorUnauthenticatedStatus(err error) bool
- func IsAPIErrorUnavailableStatus(err error) bool
- func IsDecodeBodyError(err error) bool
- func IsEncodeBodyError(err error) bool
- func IsInvalidContentTypeError(err error) bool
- func IsTransportError(err error) bool
- func IsUnexpectedStatusCodeError(err error) bool
- type APIError
- type DecodeBodyError
- type Details
- type EncodeBodyError
- type InvalidContentTypeError
- type RetryPolicy
- type Status
- type TransportError
- type UnexpectedStatusCodeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAPIError ¶
IsAPIError checks if the error is or wraps an APIError.
func IsAPIErrorAlreadyExistsStatus ¶
IsAPIErrorAlreadyExistsStatus checks if the error is an APIError with AlreadyExists status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorCancelledStatus ¶
IsAPIErrorCancelledStatus checks if the error is an APIError with Cancelled status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorDeadlineExceededStatus ¶
IsAPIErrorDeadlineExceededStatus checks if the error is an APIError with DeadlineExceeded status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorFailedPreconditionStatus ¶
IsAPIErrorFailedPreconditionStatus checks if the error is an APIError with FailedPrecondition status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorIdempotencyKeyAlreadyUsedStatus ¶
IsAPIErrorIdempotencyKeyAlreadyUsedStatus checks if the error is an APIError with IdempotencyKeyAlreadyUsed status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorInternalStatus ¶
IsAPIErrorInternalStatus checks if the error is an APIError with Internal status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorInvalidArgumentStatus ¶
IsAPIErrorInvalidArgumentStatus checks if the error is an APIError with InvalidArgument status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorInvalidEtagKeyStatus ¶
IsAPIErrorInvalidEtagKeyStatus checks if the error is an APIError with InvalidEtagKey status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorMethodNotAllowedStatus ¶
IsAPIErrorMethodNotAllowedStatus checks if the error is an APIError with MethodNotAllowed status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorNotFoundStatus ¶
IsAPIErrorNotFoundStatus checks if the error is an APIError with NotFound status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorPermissionDeniedStatus ¶
IsAPIErrorPermissionDeniedStatus checks if the error is an APIError with PermissionDenied status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorQuotaExceededStatus ¶
IsAPIErrorQuotaExceededStatus checks if the error is an APIError with QuotaExceeded status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorTooManyRequestsStatus ¶
IsAPIErrorTooManyRequestsStatus checks if the error is an APIError with TooManyRequests status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorUnauthenticatedStatus ¶
IsAPIErrorUnauthenticatedStatus checks if the error is an APIError with Unauthenticated status. Returns false if the error is not an APIError or has a different status.
func IsAPIErrorUnavailableStatus ¶
IsAPIErrorUnavailableStatus checks if the error is an APIError with Unavailable status. Returns false if the error is not an APIError or has a different status.
func IsDecodeBodyError ¶
IsDecodeBodyError checks if an error is a DecodeBodyError.
func IsEncodeBodyError ¶
IsEncodeBodyError checks if an error is a EncodeBodyError.
func IsInvalidContentTypeError ¶
IsInvalidContentTypeError checks if an error is a InvalidContentTypeError.
func IsTransportError ¶
IsTransportError checks if an error is a TransportError.
func IsUnexpectedStatusCodeError ¶
IsUnexpectedStatusCodeError checks if an error is a UnexpectedStatusCodeError.
Types ¶
type APIError ¶
type APIError struct {
// HTTP status code (e.g., 400, 404, 500).
Code int
// Typed error status for programmatic handling.
Status Status
// Human-readable error description.
Description string
// Retry policy suggested by the API.
RetryPolicy *RetryPolicy
// Additional human-readable error context. Not suitable for automated
// processing.
Details Details
}
APIError represents an error response from the API. Returned by the client when the API returns an error response.
func NewAPIError ¶
NewAPIError creates a new API error.
func (*APIError) Error ¶
Error implements the error interface for APIError. Constructs a formatted error string based on available fields.
func (*APIError) Is ¶
Is checks if the given error is an APIError. Implements the interface for error comparison using errors.Is.
func (*APIError) StatusString ¶
StatusString returns the string representation of the error status.
type DecodeBodyError ¶
type DecodeBodyError struct {
// Content-Type from the response header.
ContentType string
// Underlying decoding error.
Err error
}
DecodeBodyError reports that client decoder was unable to decode the body.
func NewDecodeBodyError ¶
func NewDecodeBodyError(contentType string, err error) *DecodeBodyError
NewDecodeBodyError creates a new decode error.
func (*DecodeBodyError) Error ¶
func (d *DecodeBodyError) Error() string
func (*DecodeBodyError) Is ¶
func (d *DecodeBodyError) Is(err error) bool
Is checks if the error is a DecodeBodyError.
func (*DecodeBodyError) Unwrap ¶
func (d *DecodeBodyError) Unwrap() error
Unwrap returns the underlying error.
type Details ¶
Details stores additional error context as key-value pairs. Intended for human-readable information, not machine processing.
type EncodeBodyError ¶
type EncodeBodyError struct {
Err error
}
EncodeBodyError reports that client got encode body error.
func NewEncodeBodyError ¶
func NewEncodeBodyError(err error) *EncodeBodyError
NewEncodeBodyError creates a new encode body error.
func (*EncodeBodyError) Error ¶
func (e *EncodeBodyError) Error() string
func (*EncodeBodyError) Is ¶
func (e *EncodeBodyError) Is(err error) bool
Is checks if the error is a EncodeBodyError.
func (*EncodeBodyError) Unwrap ¶
func (e *EncodeBodyError) Unwrap() error
Unwrap returns the underlying error.
type InvalidContentTypeError ¶
type InvalidContentTypeError struct {
ContentType string
}
InvalidContentTypeError reports that client decoder got invalid content-type.
func NewInvalidContentTypeError ¶
func NewInvalidContentTypeError(contentType string) *InvalidContentTypeError
NewInvalidContentTypeError creates a new invalid content type error.
func (*InvalidContentTypeError) Error ¶
func (e *InvalidContentTypeError) Error() string
func (*InvalidContentTypeError) Is ¶
func (e *InvalidContentTypeError) Is(err error) bool
Is checks if the error is a InvalidContentTypeError.
type RetryPolicy ¶
type RetryPolicy struct {
// Maximum total time allowed for all retry attempts.
MaxRetryTimeout time.Duration
// Maximum number of retry attempts.
RetryCount int
// Base timeout between retry attempts.
RetryTimeout time.Duration
// Multiplier for scaling timeout between consecutive retries.
RetryTimeoutScale backoff.Scale
}
RetryPolicy defines retry behavior for API errors. Used by clients to determine when and how to retry failed requests.
type Status ¶
type Status uint8
Status represents an APIError status.
type TransportError ¶
type TransportError struct {
Err error
}
TransportError reports that client got transport error.
func NewTransportError ¶
func NewTransportError(err error) *TransportError
NewTransportError creates a new transport error.
func (*TransportError) Error ¶
func (t *TransportError) Error() string
func (*TransportError) Is ¶
func (t *TransportError) Is(err error) bool
Is checks if the error is a TransportError.
func (*TransportError) Unwrap ¶
func (t *TransportError) Unwrap() error
Unwrap returns the underlying error.
type UnexpectedStatusCodeError ¶
UnexpectedStatusCodeError reports that client got unexpected status code.
func NewUnexpectedStatusCodeError ¶
func NewUnexpectedStatusCodeError(statusCode int) *UnexpectedStatusCodeError
NewUnexpectedStatusCodeError creates a new unexpected status code error.
func NewUnexpectedStatusCodeErrorWithData ¶
func NewUnexpectedStatusCodeErrorWithData(statusCode int, data []byte) *UnexpectedStatusCodeError
NewUnexpectedStatusCodeErrorWithData creates a new unexpected status code error with data.
func (*UnexpectedStatusCodeError) Error ¶
func (e *UnexpectedStatusCodeError) Error() string
func (*UnexpectedStatusCodeError) Is ¶
func (e *UnexpectedStatusCodeError) Is(err error) bool
Is checks if the error is a UnexpectedStatusCodeError.