saError

package
v0.0.0-...-b2602dc Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

error

介绍
  • 定义常用error code
  • 追踪调用文件及代码行数

Documentation

Overview

Package saError 一般建议: 各项目自行定义code值及对应的返回给前端的错误信息 业务代码内不固定错误文案 Msg是错误信息,只打印到日志

Index

Constants

View Source
const (
	SensitiveErrorCode = 1001 //错误信息包含敏感信息

	BeDisplayedErrorCode = 2000 //一般可以展示给C端用户
	NormalErrorCode      = 3000 //一般可以展示给B端用户

	LoggedFailErrorCode = 3100 //登录失效
	UnLoggedErrorCode   = 3101 //未登录
	UnAuthedErrorCode   = 3102 //未授权
	OutOfRange          = 3105 //超出范围
	ConflictErrorCode   = 3106 //有冲突
	ExistedErrorCode    = 3107 //已存在,重复
	NotExistedErrorCode = 3108 //不存在
)

Variables

View Source
var (
	ErrTooFrequent  = Error{Code: BeDisplayedErrorCode, Msg: "操作太频繁"}
	ErrParams       = Error{Code: NormalErrorCode, Msg: "缺少必要参数"}
	ErrExisted      = Error{Code: ExistedErrorCode, Msg: "数据已存在"}
	ErrNotExisted   = Error{Code: NormalErrorCode, Msg: "数据不存在"}
	ErrData         = Error{Code: NormalErrorCode, Msg: "数据有误"}
	ErrNotSupport   = Error{Code: NormalErrorCode, Msg: "暂不支持"}
	ErrPassword     = Error{Code: LoggedFailErrorCode, Msg: "账号、密码不匹配"}
	ErrLoggedFail   = Error{Code: LoggedFailErrorCode, Msg: "登录失效"}
	ErrUnLogged     = Error{Code: UnLoggedErrorCode, Msg: "未登录"}
	ErrUnauthorized = Error{Code: UnAuthedErrorCode, Msg: "未授权"}
)

Functions

func DbErr

func DbErr(err error) bool

func Msg

func Msg(e error) string

func NewBeDisplayedError

func NewBeDisplayedError(err string) error

func NewError

func NewError(err interface{}) error

err只接收字符串和error类型

func NewSensitiveError

func NewSensitiveError(err interface{}) error

err只接收字符串和error类型

func StackError

func StackError(err interface{}, params ...interface{}) error

*

  • @params err 可接收string和error类型
  • @params params 可接收int,string,error类型
  • 注意:params参数会覆盖err中相同类型数据
  • 常见用法:err传字符串,params空 -> code则是NormalErrorCode,msg为传的字符串
  • 常见用法:err传字符串,params传code值 -> 则是Error{code, msg}类型
  • 常见用法:err传err,其他为空 -> code则是SensitiveErrorCode,msg为err.error()

Types

type Error

type Error struct {
	Code   int    `json:"code"`
	Msg    string `json:"msg"`
	Caller string `json:"caller"`
}

func (Error) Error

func (e Error) Error() string

implements the error

func (Error) String

func (e Error) String() string

Jump to

Keyboard shortcuts

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