apierror

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

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

func IsTerminalError(err error) bool

IsTerminalError returns true if the error is a terminal error

func NewTerminalError

func NewTerminalError(err error) error

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

type RequestIDError struct {
	Err        error
	ResponseID *string
}

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

Jump to

Keyboard shortcuts

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