errors

package
v2.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 7 Imported by: 8

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 to 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.

View Source
const MaxPasswordLen = 72
View Source
const MinPasswordLen int = 8
View Source
const SpecialChars = `!@#$%^&*()_+`

Variables

View Source
var (
	// ErrUserNotFound is used when the user is not found.
	ErrUserNotFound = &Error{
		Msg:  "user not found",
		Code: ENotFound,
	}

	// EIncorrectPassword is returned when any password operation fails in which
	// we do not want to leak information.
	EIncorrectPassword = &Error{
		Code: EForbidden,
		Msg:  "your username or password is incorrect",
	}

	// EIncorrectUser is returned when any user is failed to be found which indicates
	// the userID provided is for a user that does not exist.
	EIncorrectUser = &Error{
		Code: EForbidden,
		Msg:  "your userID is incorrect",
	}

	// EPasswordLength is used when a password is less than the minimum
	// acceptable password length or longer than the maximum acceptable password length
	EPasswordLength = &Error{
		Code: EInvalid,
		Msg:  fmt.Sprintf("passwords must be between %d and %d characters long", MinPasswordLen, MaxPasswordLen),
	}

	EPasswordChars = &Error{
		Code: EInvalid,
		Msg: fmt.Sprintf(
			"passwords must contain at least three of the following character types: uppercase, lowercase, numbers, and special characters: %s",
			SpecialChars),
	}

	EPasswordChangeRequired = &Error{
		Code: EForbidden,
		Msg:  "password change required",
	}
)

Functions

func BoltToInfluxError added in v2.7.5

func BoltToInfluxError(err error) error

func ErrInternalServiceError added in v2.7.5

func ErrInternalServiceError(err error, options ...func(*Error)) error

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 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 ErrCorruptUser added in v2.7.6

func ErrCorruptUser(err error) *Error

ErrCorruptUser is used when the user cannot be unmarshalled from the bytes stored in the kv.

func ErrUnprocessableUser added in v2.7.6

func ErrUnprocessableUser(err error) *Error

ErrUnprocessableUser is used when a user is not able to be processed.

func InvalidUserIDError added in v2.7.6

func InvalidUserIDError(err error) *Error

InvalidUserIDError is used when a service was provided an invalid ID. This is some sort of internal server error.

func NewError

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

NewError returns an instance of an error.

func UnavailablePasswordServiceError added in v2.7.6

func UnavailablePasswordServiceError(err error) *Error

UnavailablePasswordServiceError is used if we aren't able to add the password to the store, it means the store is not available at the moment (e.g. network).

func UnexpectedUserBucketError added in v2.7.6

func UnexpectedUserBucketError(err error) *Error

UnexpectedUserBucketError is used when the error comes from an internal system.

func UnexpectedUserIndexError added in v2.7.6

func UnexpectedUserIndexError(err error) *Error

UnexpectedUserIndexError is used when the error comes from an internal system.

func UserAlreadyExistsError added in v2.7.6

func UserAlreadyExistsError(n string) *Error

UserAlreadyExistsError is used when attempting to create a user with a name that already exists.

func UserIDAlreadyExistsError added in v2.7.6

func UserIDAlreadyExistsError(id string) *Error

UserIDAlreadyExistsError is used when attempting to create a user with an ID that already exists.

func (*Error) Copy added in v2.7.5

func (err *Error) Copy() *Error

func (*Error) Error

func (e *Error) Error() string

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

func (*Error) Is added in v2.7.5

func (e *Error) Is(err error) bool

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.

func (*Error) Unwrap added in v2.7.5

func (err *Error) Unwrap() error

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