errcode

package
v0.0.0-...-823317f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Unlicense Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorCodeUnknown = Register("errcode", ErrorDescriptor{
		Value:          "UNKNOWN",
		Message:        "unknown error",
		Description:    "Generic error returned when the error does not have a classification.",
		HTTPStatusCode: http.StatusInternalServerError,
	})

	ErrorCodeUnsupported = Register("errcode", ErrorDescriptor{
		Value:          "UNSUPPORTED",
		Message:        "the operation is unsupported",
		Description:    "The operation was unsupported due to invalid parameters or missing implementation.",
		HTTPStatusCode: http.StatusMethodNotAllowed,
	})
)

Functions

func ServeJSON

func ServeJSON(w http.ResponseWriter, err error) error

Types

type Error

type Error struct {
	Code    ErrorCode   `json:"code"`
	Message string      `json:"message"`
	Detail  interface{} `json:"detail,omitempty"`
}

func (Error) Error

func (e Error) Error() string

func (Error) ErrorCode

func (e Error) ErrorCode() ErrorCode

func (Error) WithArgs

func (e Error) WithArgs(args ...interface{}) Error

func (Error) WithDetail

func (e Error) WithDetail(detail interface{}) Error

type ErrorCode

type ErrorCode int

func Register

func Register(group string, descriptor ErrorDescriptor) ErrorCode

func (ErrorCode) Descriptor

func (ec ErrorCode) Descriptor() ErrorDescriptor

func (ErrorCode) Error

func (ec ErrorCode) Error() string

func (ErrorCode) ErrorCode

func (ec ErrorCode) ErrorCode() ErrorCode

func (ErrorCode) MarshalText

func (ec ErrorCode) MarshalText() ([]byte, error)

func (ErrorCode) Message

func (ec ErrorCode) Message() string

func (ErrorCode) String

func (ec ErrorCode) String() string

func (*ErrorCode) UnmarshalText

func (ec *ErrorCode) UnmarshalText(text []byte) error

func (ErrorCode) WithArgs

func (ec ErrorCode) WithArgs(args ...interface{}) Error

func (ErrorCode) WithDetail

func (ec ErrorCode) WithDetail(detail interface{}) Error

func (ErrorCode) WithMessage

func (ec ErrorCode) WithMessage(message string) Error

type ErrorCoder

type ErrorCoder interface {
	ErrorCode() ErrorCode
}

type ErrorDescriptor

type ErrorDescriptor struct {
	Code           ErrorCode
	Value          string
	Message        string
	Description    string
	HTTPStatusCode int
}

type Errors

type Errors []error

func (Errors) Error

func (errs Errors) Error() string

func (Errors) Len

func (errs Errors) Len() int

func (Errors) MarshalJSON

func (errs Errors) MarshalJSON() ([]byte, error)

func (*Errors) UnmarshalJSON

func (errs *Errors) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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