errors

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 通用错误码
	PARAM_ERROR     = 1   //参数错误
	SYSTEM_ERROR    = 2   //服务内部错误
	USER_NOT_LOGIN  = 3   //用户未登录
	INVALID_REQUEST = 6   //无效请求
	DEFAULT_ERROR   = 100 //默认错误,未准出的错误码,会修改为此错误码
	CUSTOM_ERROR    = 101 //自定义错误,无固定错误文案
)

标准准出错误码定义

Variables

View Source
var ErrMsg = map[int]string{

	PARAM_ERROR:     "请求参数错误",
	SYSTEM_ERROR:    "服务异常,请稍后重试",
	USER_NOT_LOGIN:  "用户Session已失效,请重新登录",
	INVALID_REQUEST: "请求无效,请稍后再试",
	DEFAULT_ERROR:   "服务开小差了,请稍后再试",
}

标准准出错误码文案定义

View Source
var ErrorCustomError = Error{
	Code:    CUSTOM_ERROR,
	Message: "%s",
}

自定义错误 使用方式:ErrorCustomError.Sprintf(v)

View Source
var ErrorDefault = Error{
	Code:    DEFAULT_ERROR,
	Message: ErrMsg[DEFAULT_ERROR],
}

默认错误

View Source
var ErrorInvalidRequest = Error{
	Code:    INVALID_REQUEST,
	Message: ErrMsg[INVALID_REQUEST],
}

无效请求

View Source
var ErrorParamInvalid = Error{
	Code:    PARAM_ERROR,
	Message: ErrMsg[PARAM_ERROR],
}

参数错误

View Source
var ErrorSuccess = Error{
	Code:    0,
	Message: "success",
}

*****以下是通用准出错误码的简便定义*********** 正常

View Source
var ErrorSystemError = Error{
	Code:    SYSTEM_ERROR,
	Message: ErrMsg[SYSTEM_ERROR],
}

系统异常

View Source
var ErrorUserNotLogin = Error{
	Code:    USER_NOT_LOGIN,
	Message: ErrMsg[USER_NOT_LOGIN],
}

用户未登录

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    int
	Message string
}

func NewError

func NewError(code int, message string) *Error

func (Error) Equal

func (err Error) Equal(e error) bool

func (Error) Error

func (err Error) Error() string

func (Error) Sprintf

func (err Error) Sprintf(v ...interface{}) Error

func (Error) Wrap

func (err Error) Wrap(core error) error

func (Error) WrapPrint

func (err Error) WrapPrint(core error, message string) error

func (Error) WrapPrintf

func (err Error) WrapPrintf(core error, format string, message ...interface{}) error

Jump to

Keyboard shortcuts

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