error

package
v0.0.0-...-f8e07d0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDetails

func AddDetails(err error, details string) error

AddDetails adds details to an existing apiError, but keeps the type and handling. If the error is not an apiError, it will wrap the error with the details.

func HTTPResponseFromError

func HTTPResponseFromError(err error) (*httpgrpc.HTTPResponse, bool)

HTTPResponseFromError converts an APIError into a JSON HTTP response

func IsAPIError

func IsAPIError(err error) bool

IsAPIError returns true if the error provided is an apiError. This implies that HTTPResponseFromError will succeed.

func IsNonRetryableAPIError

func IsNonRetryableAPIError(err error) bool

IsNonRetryableAPIError returns true if err is an apiError which should be failed and not retried.

Types

type APIError

type APIError struct {
	Type    Type
	Message string
}

func New

func New(typ Type, msg string) *APIError

New creates a new apiError with a static string message

func Newf

func Newf(typ Type, tmpl string, args ...interface{}) *APIError

Newf creates a new apiError with a formatted message

func (*APIError) EncodeJSON

func (e *APIError) EncodeJSON() ([]byte, error)

func (*APIError) Error

func (e *APIError) Error() string

type Type

type Type string
const (
	TypeNone            Type = ""
	TypeTimeout         Type = "timeout"
	TypeCanceled        Type = "canceled"
	TypeExec            Type = "execution"
	TypeBadData         Type = "bad_data"
	TypeInternal        Type = "internal"
	TypeUnavailable     Type = "unavailable"
	TypeNotFound        Type = "not_found"
	TypeTooManyRequests Type = "too_many_requests"
	TypeTooLargeEntry   Type = "too_large_entry"
	TypeNotAcceptable   Type = "not_acceptable"
)

adapted from https://github.com/prometheus/prometheus/blob/fdbc40a9efcc8197a94f23f0e479b0b56e52d424/web/api/v1/api.go#L67-L76

Jump to

Keyboard shortcuts

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