Documentation
¶
Overview ¶
Package apierror provides a consistent way to handle errors from API calls
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
func CheckResponse[T any](resp APIResponse[T], err error) (*T, error)
CheckResponse checks the response for errors and returns the value or an error
func IsTerminalError ¶
IsTerminalError returns true if the error is a terminal error
func NewTerminalError ¶
NewTerminalError creates a new terminal error that cannot be retried
Types ¶
type APIResponse ¶
type APIResponse[T any] interface { // GetHTTPResponse returns the HTTP response GetHTTPResponse() *http.Response // GetInternalServerError returns the internal server error GetInternalServerError() (string, bool) // GetBadRequestError returns the bad request error GetBadRequestError() (string, bool) // GetValue returns the value GetValue() *T }
APIResponse is the interface that wraps the response from an API call
type Error ¶
type Error interface {
GetError() string
}
Error is the interface that wraps the error returned from an API call
type RequestIDError ¶
RequestIDError is an error that wraps another error and includes the response ID
func WithRequestID ¶
func WithRequestID(err error, headers http.Header) *RequestIDError
WithRequestID creates a new RequestIDError
func (*RequestIDError) Error ¶
func (e *RequestIDError) Error() string
Error implements error for RequestIDError
func (*RequestIDError) Is ¶
func (e *RequestIDError) Is(err error) bool
Is implements errors.Is for RequestIDError
func (*RequestIDError) Unwrap ¶
func (e *RequestIDError) Unwrap() error
Unwrap implements errors.Unwrap for RequestIDError