errors

package
v0.0.0-...-50176c9 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

README

错误

包括不可变错误 ConstError 和 用用于http api 返回的 Auth,Dumplicated,IllegalArgumentNotFound error。

ConstError

该error不可变,errors.ConstError("错误") 即可得到一个不可变的error对象。

CodeError

该error 含有 codemsg 两个参数,code 用于返回具体的错误代码,msg 其他错误的结构体组合了 CodeError结构体,同时提供了NewXXX的方法,比如 要得到一个Auth error,errors.NewAuth(401,"密码错误") 即可。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFoundError        = NewNotFound(0, "not found")
	DuplicatedError      = NewDuplicated(0, "already exists")
	IllegalArgumentError = NewIllegalArgument(0, "illegal argument")
)

Functions

func NewForbidden

func NewForbidden(code int, msgs ...string) error

NewForbidden 新建

func NewUnauthorized

func NewUnauthorized(code int, msgs ...string) error

NewUnauthorized 新建

func Panic

func Panic(err error, msgs ...string)

Panic 如果err 不是nil,则panic 如果msgs 有填写,则panic msgs+err.Error()

Types

type CodeError

type CodeError struct {
	Log  string `json:"-"` // record log, not show for user
	Msg  string `json:"msg"`
	Code int    `json:"code"`
}

CodeError 带错误码的错误

func NewCode

func NewCode(code int, msgs ...string) CodeError

NewCode 新建一个error

func (CodeError) AddMsg

func (e CodeError) AddMsg(msgs ...string) CodeError

func (CodeError) Error

func (e CodeError) Error() string

func (CodeError) GetCode

func (e CodeError) GetCode() int

func (CodeError) GetLog

func (e CodeError) GetLog() string

func (CodeError) GetMsg

func (e CodeError) GetMsg() string

type ConstError

type ConstError string

ConstError 不可变error

func (ConstError) Error

func (e ConstError) Error() string

type Duplicated

type Duplicated struct {
	// contains filtered or unexported fields
}

Duplicated 重复

func NewDuplicated

func NewDuplicated(code int, msgs ...string) Duplicated

NewDuplicated 新建

func (Duplicated) AddMsg

func (e Duplicated) AddMsg(msgs ...string) Duplicated

func (Duplicated) Error

func (e Duplicated) Error() string

func (Duplicated) GetCode

func (e Duplicated) GetCode() int

func (Duplicated) GetLog

func (e Duplicated) GetLog() string

func (Duplicated) GetMsg

func (e Duplicated) GetMsg() string

type Forbidden

type Forbidden struct {
	// contains filtered or unexported fields
}

Forbidden 权限错误

func (Forbidden) AddMsg

func (e Forbidden) AddMsg(msgs ...string) Forbidden

func (Forbidden) Error

func (e Forbidden) Error() string

func (Forbidden) GetCode

func (e Forbidden) GetCode() int

func (Forbidden) GetLog

func (e Forbidden) GetLog() string

func (Forbidden) GetMsg

func (e Forbidden) GetMsg() string

type IllegalArgument

type IllegalArgument struct {
	// contains filtered or unexported fields
}

IllegalArgument 参数不合法

func NewIllegalArgument

func NewIllegalArgument(code int, msgs ...string) IllegalArgument

NewIllegalArgument 新建

func (IllegalArgument) AddMsg

func (e IllegalArgument) AddMsg(msgs ...string) IllegalArgument

func (IllegalArgument) Error

func (e IllegalArgument) Error() string

func (IllegalArgument) GetCode

func (e IllegalArgument) GetCode() int

func (IllegalArgument) GetLog

func (e IllegalArgument) GetLog() string

func (IllegalArgument) GetMsg

func (e IllegalArgument) GetMsg() string

type NotFound

type NotFound struct {
	// contains filtered or unexported fields
}

NotFound 找不到

func NewNotFound

func NewNotFound(code int, msgs ...string) NotFound

NewNotFound 新建

func (NotFound) AddMsg

func (e NotFound) AddMsg(msgs ...string) NotFound

func (NotFound) Error

func (e NotFound) Error() string

func (NotFound) GetCode

func (e NotFound) GetCode() int

func (NotFound) GetLog

func (e NotFound) GetLog() string

func (NotFound) GetMsg

func (e NotFound) GetMsg() string

type Unauthorized

type Unauthorized struct {
	// contains filtered or unexported fields
}

Unauthorized 权限错误

func (Unauthorized) AddMsg

func (e Unauthorized) AddMsg(msgs ...string) Unauthorized

func (Unauthorized) Error

func (e Unauthorized) Error() string

func (Unauthorized) GetCode

func (e Unauthorized) GetCode() int

func (Unauthorized) GetLog

func (e Unauthorized) GetLog() string

func (Unauthorized) GetMsg

func (e Unauthorized) GetMsg() string

Jump to

Keyboard shortcuts

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