errors

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package errors provides types and utilities for API errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAPIError

func IsAPIError(err error) bool

IsAPIError checks if the error is or wraps an APIError.

func IsAPIErrorAlreadyExistsStatus

func IsAPIErrorAlreadyExistsStatus(err error) bool

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

func IsAPIErrorCancelledStatus(err error) bool

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

func IsAPIErrorDeadlineExceededStatus(err error) bool

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

func IsAPIErrorFailedPreconditionStatus(err error) bool

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

func IsAPIErrorIdempotencyKeyAlreadyUsedStatus(err error) bool

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

func IsAPIErrorInternalStatus(err error) bool

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

func IsAPIErrorInvalidArgumentStatus(err error) bool

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

func IsAPIErrorInvalidEtagKeyStatus(err error) bool

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

func IsAPIErrorMethodNotAllowedStatus(err error) bool

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

func IsAPIErrorNotFoundStatus(err error) bool

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

func IsAPIErrorPermissionDeniedStatus(err error) bool

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

func IsAPIErrorQuotaExceededStatus(err error) bool

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

func IsAPIErrorTooManyRequestsStatus(err error) bool

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

func IsAPIErrorUnauthenticatedStatus(err error) bool

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

func IsAPIErrorUnavailableStatus(err error) bool

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

func IsDecodeBodyError(err error) bool

IsDecodeBodyError checks if an error is a DecodeBodyError.

func IsEncodeBodyError

func IsEncodeBodyError(err error) bool

IsEncodeBodyError checks if an error is a EncodeBodyError.

func IsInvalidContentTypeError

func IsInvalidContentTypeError(err error) bool

IsInvalidContentTypeError checks if an error is a InvalidContentTypeError.

func IsTransportError

func IsTransportError(err error) bool

IsTransportError checks if an error is a TransportError.

func IsUnexpectedStatusCodeError

func IsUnexpectedStatusCodeError(err error) bool

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

func NewAPIError(code int, status Status, description string) *APIError

NewAPIError creates a new API error.

func (*APIError) Error

func (a *APIError) Error() string

Error implements the error interface for APIError. Constructs a formatted error string based on available fields.

func (*APIError) Is

func (a *APIError) Is(err error) bool

Is checks if the given error is an APIError. Implements the interface for error comparison using errors.Is.

func (*APIError) StatusString

func (a *APIError) StatusString() string

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

type Details map[string]any

Details stores additional error context as key-value pairs. Intended for human-readable information, not machine processing.

func (Details) String

func (d Details) String() string

String returns a flattened JSON representation of the details.

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.

const (
	Unknown Status = iota
	AlreadyExists
	Cancelled
	DeadlineExceeded
	FailedPrecondition
	Internal
	InvalidArgument
	NotFound
	PermissionDenied
	QuotaExceeded
	IdempotencyKeyAlreadyUsed
	InvalidEtagKey
	Unauthenticated
	Unavailable
	MethodNotAllowed
	TooManyRequests
)

func (Status) HTTPCodes

func (s Status) HTTPCodes() []int

HTTPCodes returns HTTP status codes associated with this error status. Some statuses may map to multiple HTTP codes depending on context.

func (Status) String

func (s Status) String() string

String returns the string representation of the 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

type UnexpectedStatusCodeError struct {
	StatusCode int
	Data       []byte
}

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

Is checks if the error is a UnexpectedStatusCodeError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL