Documentation ¶
Index ¶
- Constants
- Variables
- func IsBadRequest(err error) bool
- func IsForbidden(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsNotImplemented(err error) bool
- func IsUnauthorized(err error) bool
- func IsUnknown(err error) bool
- func WithBadRequest(err error, formatWithArgs ...interface{}) error
- func WithErrorMessage(c *ErrCode, err error, formatWithArgs ...interface{}) error
- func WithForbidden(err error, formatWithArgs ...interface{}) error
- func WithInternalServer(err error, formatWithArgs ...interface{}) error
- func WithNotFound(err error, formatWithArgs ...interface{}) error
- func WithNotImplemented(err error, formatWithArgs ...interface{}) error
- func WithSessionMessage(err error, formatWithArgs ...interface{}) error
- func WithUnauthorized(err error, formatWithArgs ...interface{}) error
- func WithUnknown(err error, formatWithArgs ...interface{}) error
- type CodeError
- type ErrCode
Constants ¶
View Source
const ( // CodeCategory CCBadRequest = errorx.CCBadRequest // 400 CCForbidden = errorx.CCForbidden // 403 CCNotFound = errorx.CCNotFound // 404 CCInternalServer = errorx.CCInternalServer // 500 CCNotImplemented = errorx.CCNotImplemented // 501 CCUnknown = errorx.CCUnknown // 900 )
View Source
const (
PlatformCode = 4
)
Variables ¶
View Source
var ( // WithCode return error warps with codeError. // c is the code. err is the real err. formatWithArgs is format string with args. // For example: // WithCode(ErrBadRequest, nil) // WithCode(ErrBadRequest, err) // WithCode(ErrBadRequest, err, "message") // WithCode(ErrBadRequest, err, "message %s", "id") WithCode = errorx.WithCode AsCodeError = errorx.AsCodeError IsCodeError = errorx.IsCodeError SeparateCode = errorx.SeparateCode TakeCodePriority = errorx.TakeCodePriority )
View Source
var ( ErrBadRequest = newErrCode(CCBadRequest, PlatformCode, 0, "ErrBadRequest") // 40004000 ErrParam = newErrCode(CCBadRequest, PlatformCode, 1, "ErrParam") // 40004001 ErrSession = newErrCode(CCUnauthorized, PlatformCode, 1, "ErrSession") // 40104001 ErrForbidden = newErrCode(CCForbidden, PlatformCode, 0, "ErrForbidden") // 40304000 ErrNotFound = newErrCode(CCNotFound, PlatformCode, 0, "ErrNotFound") // 40404000 ErrInternalServer = newErrCode(CCInternalServer, PlatformCode, 0, "ErrInternalServer") // 50004000 ErrInternalDatabase = newErrCode(CCInternalServer, PlatformCode, 1, "ErrInternalDatabase") // 50004001 ErrInternalAlreadyExist = newErrCode(CCInternalServer, PlatformCode, 2, "ErrAlreadyExists") // 50004001 ErrMultiplePrimaryFields = newErrCode(CCInternalServer, PlatformCode, 3, "ErrMultiplePrimaryField") // 50004001 ErrNotImplemented = newErrCode(CCNotImplemented, PlatformCode, 0, "ErrNotImplemented") // 50104000 ErrUnknown = newErrCode(CCUnknown, PlatformCode, 0, "ErrUnknown") // 90004000 )
Define you error code here
Functions ¶
func IsBadRequest ¶
func IsForbidden ¶
func IsInternalServer ¶
func IsNotFound ¶
func IsNotImplemented ¶
func IsUnauthorized ¶
func WithBadRequest ¶
func WithErrorMessage ¶
func WithForbidden ¶
func WithInternalServer ¶
func WithNotFound ¶
func WithNotImplemented ¶
func WithSessionMessage ¶
func WithUnauthorized ¶
func WithUnknown ¶
Types ¶
type ErrCode ¶
ErrCode is the error code for app 0 indicates success, others indicate failure. It is combined of error category code, platform code, and specific code via CodeCombiner. The default CodeCombiner's rules are as follows:
- The first three digits represent the category code, analogous to the http status code.
- The next two digits indicate the platform code.
- The last three digits indicate the specific code. For example: 4041001: 404 is the error category code 10 is the error platform code 001 is the error specific code
func GetErrCodeByHTTPStatus ¶
Click to show internal directories.
Click to hide internal directories.