ecode

package
v1.1.70 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeCategory
	CCBadRequest     = errorx.CCBadRequest     // 400
	CCUnauthorized   = errorx.CCUnauthorized   // 401
	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
	ErrUnauthorized          = newErrCode(CCUnauthorized, PlatformCode, 0, "ErrUnauthorized")           // 40104000
	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 IsBadRequest(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsInternalServer

func IsInternalServer(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsNotImplemented

func IsNotImplemented(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func IsUnknown

func IsUnknown(err error) bool

func WithBadRequest

func WithBadRequest(err error, formatWithArgs ...interface{}) error

func WithErrorMessage

func WithErrorMessage(c *ErrCode, err error, formatWithArgs ...interface{}) error

func WithForbidden

func WithForbidden(err error, formatWithArgs ...interface{}) error

func WithInternalServer

func WithInternalServer(err error, formatWithArgs ...interface{}) error

func WithNotFound

func WithNotFound(err error, formatWithArgs ...interface{}) error

func WithNotImplemented

func WithNotImplemented(err error, formatWithArgs ...interface{}) error

func WithSessionMessage

func WithSessionMessage(err error, formatWithArgs ...interface{}) error

func WithUnauthorized

func WithUnauthorized(err error, formatWithArgs ...interface{}) error

func WithUnknown

func WithUnknown(err error, formatWithArgs ...interface{}) error

Types

type CodeError

type CodeError = errorx.CodeError

type ErrCode

type ErrCode = errorx.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

func GetErrCodeByHTTPStatus(httpStatus int) *ErrCode

Jump to

Keyboard shortcuts

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