Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( OK = &ErrDef{Code: 0, Msg: "OK", HttpStatus: http.StatusOK} InternalServerError = &ErrDef{Code: 10001, Msg: "Internal server error.", HttpStatus: http.StatusForbidden} ErrBind = &ErrDef{ Code: 10002, Msg: "Error occurred while binding the request body to the struct.", HttpStatus: http.StatusBadRequest, } ErrParams = &ErrDef{Code: 10003, Msg: "Error params.", HttpStatus: http.StatusBadRequest} ErrParse = &ErrDef{Code: 10004, Msg: "Error parse.", HttpStatus: http.StatusBadRequest} // ErrValidation database errors ErrValidation = &ErrDef{Code: 20001, Msg: "Validation failed.", HttpStatus: http.StatusUnauthorized} ErrDatabase = &ErrDef{Code: 20002, Msg: "Database error.", HttpStatus: http.StatusForbidden} ErrToken = &ErrDef{Code: 20003, Msg: "Error occurred while signing the JSON web token.", HttpStatus: http.StatusUnauthorized, } // ErrEncrypt // user errors ErrEncrypt = &ErrDef{Code: 20101, Msg: "Error occurred while encrypting the user password.", HttpStatus: http.StatusBadRequest, } ErrUserNotFound = &ErrDef{Code: 20102, Msg: "The user was not found.", HttpStatus: http.StatusUnauthorized} ErrTokenInvalid = &ErrDef{Code: 20103, Msg: "The token was invalid.", HttpStatus: http.StatusUnauthorized} ErrPasswordIncorrect = &ErrDef{Code: 20104, Msg: "The password was incorrect.", HttpStatus: http.StatusUnauthorized} )
Common errors, each error must have HttpStatus!
Functions ¶
func IsEqualByCode ¶
IsEqualByCode asset error is code to use errdef.DecodeErr()
func IsErrUserNotFound ¶
IsErrUserNotFound asset error is ErrUserNotFound to use errdef.DecodeErr()
Types ¶
type Err ¶
type Err struct {
// Code
// error code default 0 is OK
Code int `json:"code" validate:"required" example:"0"`
// Msg
// error message, if OK is empty
Msg string `json:"msg" validate:"optional" example:"msg of error code 0 is empty"`
Err error `json:"-"`
}
Err represents an error only show in log, but not to client
func New ¶
New new error for use e errdef.ErrDef in $project/pkg/errdef/ file e.go, you can add more! err error can use fmt.Errorf() to create use like errdef.New(errdef.InternalServerError, fmt.Errorf("server error, err: %v", err)) and you can add message errdef.New(errdef.InternalServerError, fmt.Errorf("server error, err: %v", err)).Add("client can know error")
func NewErr ¶
NewErr new error for use e errdef.ErrDef in $project/pkg/errdef/ file e.go, you can add more! use like errdef.NewErr(errdef.ErrParams) and you can add message
errdef.NewErr(errdef.ErrParams).Add("params id not found")
type ErrDef ¶
type ErrDef struct {
// Code
// error code default 0 is OK
Code int `json:"code" validate:"required" example:"0"`
// Msg
// error message, if OK is empty
Msg string `json:"msg" validate:"optional" example:"msg of error code 0 is empty"`
// HttpStatus
// http status code, this is set by config
HttpStatus int `json:"-"`
}