Help us shape the future of Go! Take the 2026 Go Developer Survey

saError

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 6 Imported by: 15

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 //不存在
)
View Source
const (
	ErrTooFrequent  = "操作太频繁"
	ErrParams       = "缺少必要参数"
	ErrExisted      = "数据已存在"
	ErrNotExisted   = "数据不存在"
	ErrData         = "数据有误"
	ErrNotSupport   = "暂不支持"
	ErrPassword     = "账号、密码不匹配"
	ErrLoggedFail   = "登录失效,请重新登录"
	ErrUnLogged     = "未登录"
	ErrUnauthorized = "未授权"
)

Variables

This section is empty.

Functions

func DbErr

func DbErr(err error) bool

func Msg

func Msg(e error) string

func New

func New(err interface{}) error

New 只接收字符串和error类型

func NewBeDisplayedError

func NewBeDisplayedError(err string) error

func NewSensitiveError

func NewSensitiveError(err interface{}) error

NewSensitiveError err只接收字符串和error类型

func SetPkg

func SetPkg(pkgPath string, ignore ...string)

func Stack

func Stack(errs ...interface{}) error

Stack @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