errors

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EInternal            = "internal error"
	ENotImplemented      = "not implemented"
	ENotFound            = "not found"
	EConflict            = "conflict"             // action cannot be performed
	EInvalid             = "invalid"              // validation failed
	EUnprocessableEntity = "unprocessable entity" // data type is correct, but out of range
	EEmptyValue          = "empty value"
	EUnavailable         = "unavailable"
	EForbidden           = "forbidden"
	ETooManyRequests     = "too many requests"
	EUnauthorized        = "unauthorized"
	EMethodNotAllowed    = "method not allowed"
	ETooLarge            = "request too large"
)

Some error code constant, ideally we want define common platform codes here projects on use platform's error, should have their own central place like this. Any time this set of constants changes, you must also update the swagger for Error.properties.code.enum.

Variables

This section is empty.

Functions

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns the code of the root error, if available; otherwise returns EINTERNAL.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.

func ErrorOp

func ErrorOp(err error) string

ErrorOp returns the op of the error, if available; otherwise return empty string.

func WithErrorCode

func WithErrorCode(code string) func(*Error)

WithErrorCode sets the code on the error.

func WithErrorErr

func WithErrorErr(err error) func(*Error)

WithErrorErr sets the err on the error.

func WithErrorMsg

func WithErrorMsg(msg string) func(*Error)

WithErrorMsg sets the message on the error.

func WithErrorOp

func WithErrorOp(op string) func(*Error)

WithErrorOp sets the message on the error.

Types

type ChronografError

type ChronografError string

ChronografError is a domain error encountered while processing chronograf requests.

func (ChronografError) Error

func (e ChronografError) Error() string

ChronografError returns the string of an error.

type Error

type Error struct {
	Code string
	Msg  string
	Op   string
	Err  error
}

Error is the error struct of platform.

Errors may have error codes, human-readable messages, and a logical stack trace.

The Code targets automated handlers so that recovery can occur. Msg is used by the system operator to help diagnose and fix the problem. Op and Err chain errors together in a logical stack trace to further help operators.

To create a simple error,

&Error{
    Code:ENotFound,
}

To show where the error happens, add Op.

&Error{
    Code: ENotFound,
    Op: "bolt.FindUserByID"
}

To show an error with a unpredictable value, add the value in Msg.

&Error{
   Code: EConflict,
   Message: fmt.Sprintf("organization with name %s already exist", aName),
}

To show an error wrapped with another error.

&Error{
    Code:EInternal,
    Err: err,
}.

func NewError

func NewError(options ...func(*Error)) *Error

NewError returns an instance of an error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface by writing out the recursive messages.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() (result []byte, err error)

MarshalJSON recursively marshals the stack of Err.

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON recursively unmarshals the error stack.

type HTTPErrorHandler

type HTTPErrorHandler interface {
	HandleHTTPError(ctx context.Context, err error, w http.ResponseWriter)
}

HTTPErrorHandler is the interface to handle http error.

Jump to

Keyboard shortcuts

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