Documentation ¶
Index ¶
- Constants
- Variables
- func BoltToInfluxError(err error) error
- func ErrInternalServiceError(err error, options ...func(*Error)) error
- func ErrorCode(err error) string
- func ErrorMessage(err error) string
- func ErrorOp(err error) string
- func WithErrorCode(code string) func(*Error)
- func WithErrorErr(err error) func(*Error)
- func WithErrorMsg(msg string) func(*Error)
- func WithErrorOp(op string) func(*Error)
- type Error
- func ErrCorruptUser(err error) *Error
- func ErrUnprocessableUser(err error) *Error
- func InvalidUserIDError(err error) *Error
- func NewError(options ...func(*Error)) *Error
- func UnavailablePasswordServiceError(err error) *Error
- func UnexpectedUserBucketError(err error) *Error
- func UnexpectedUserIndexError(err error) *Error
- func UserAlreadyExistsError(n string) *Error
- func UserIDAlreadyExistsError(id string) *Error
- type HTTPErrorHandler
Constants ¶
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" EForbidden = "forbidden" ETooManyRequests = "too many requests" 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.
const MaxPasswordLen = 72
const MinPasswordLen int = 8
const SpecialChars = `!@#$%^&*()_+`
Variables ¶
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 ErrInternalServiceError ¶ added in v2.7.5
func ErrorCode ¶
ErrorCode returns the code of the root error, if available; otherwise returns EINTERNAL.
func ErrorMessage ¶
ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.
func WithErrorCode ¶
WithErrorCode sets the code on the error.
func WithErrorErr ¶
WithErrorErr sets the err on the error.
func WithErrorMsg ¶
WithErrorMsg sets the message on the error.
func WithErrorOp ¶
WithErrorOp sets the message on the error.
Types ¶
type 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
ErrCorruptUser is used when the user cannot be unmarshalled from the bytes stored in the kv.
func ErrUnprocessableUser ¶ added in v2.7.6
ErrUnprocessableUser is used when a user is not able to be processed.
func InvalidUserIDError ¶ added in v2.7.6
InvalidUserIDError is used when a service was provided an invalid ID. This is some sort of internal server error.
func UnavailablePasswordServiceError ¶ added in v2.7.6
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
UnexpectedUserBucketError is used when the error comes from an internal system.
func UnexpectedUserIndexError ¶ added in v2.7.6
UnexpectedUserIndexError is used when the error comes from an internal system.
func UserAlreadyExistsError ¶ added in v2.7.6
UserAlreadyExistsError is used when attempting to create a user with a name that already exists.
func UserIDAlreadyExistsError ¶ added in v2.7.6
UserIDAlreadyExistsError is used when attempting to create a user with an ID that already exists.
func (*Error) MarshalJSON ¶
MarshalJSON recursively marshals the stack of Err.
func (*Error) UnmarshalJSON ¶
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.