errors

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: Apache-2.0 Imports: 8 Imported by: 128

README

概要

Code Error 是一个继承标准 error 并增加 code 内容进行扩展的错误结构。

获取

go get github.com/aacfactory/errors

使用

// 基本使用
err := errors.NewCodeError(500, "***FOO***", "bar")
fmt.Println(err)
// json 输出
v, _ := json.Marshal(err)
fmt.Println(string(v))

// http status 使用环境
err := errors.InvalidArgumentError("参数错误")
err := errors.InvalidArgumentErrorWithDetails("参数错误", "email", "非法 Email 格式")
err := errors.UnauthorizedError("未认证")
err := errors.ForbiddenError("拒绝访问")
err := errors.ForbiddenErrorWithReason("拒绝访问", "普通用户", "机密文件", "保险箱")
err := errors.NotFoundError("404")
err := errors.ServiceError("服务处理失败")
err := errors.NotImplementedError("功能未实现")
err := errors.UnavailableError("服务不可用")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeError

type CodeError interface {
	SetId(id string) CodeError
	SetFailureCode(failureCode int) CodeError
	GetMeta() MultiMap
	GetStacktrace() (fn string, file string, line int)
	Error() string
	String() string
	ToJson() []byte
}

func ForbiddenError

func ForbiddenError(message string) CodeError

func ForbiddenErrorWithReason

func ForbiddenErrorWithReason(message string, role string, resource ...string) CodeError

func FromJson added in v1.1.0

func FromJson(v []byte) (codeErr CodeError, ok bool)

func InvalidArgumentError

func InvalidArgumentError(message string) CodeError

func InvalidArgumentErrorWithDetails

func InvalidArgumentErrorWithDetails(message string, details ...string) CodeError

func NewCodeError

func NewCodeError(failureCode int, code string, message string) CodeError

func NotFoundError

func NotFoundError(message string) CodeError

func NotImplementedError

func NotImplementedError(message string) CodeError

func ServiceError

func ServiceError(message string) CodeError

func Transfer added in v1.1.0

func Transfer(err error) (codeErr CodeError, ok bool)

func UnauthorizedError

func UnauthorizedError(message string) CodeError

func UnavailableError

func UnavailableError(message string) CodeError

type MultiMap

type MultiMap map[string][]string

func (MultiMap) Add

func (h MultiMap) Add(key string, value string)

func (MultiMap) Empty

func (h MultiMap) Empty() bool

func (MultiMap) Get

func (h MultiMap) Get(key string) (string, bool)

func (MultiMap) Keys

func (h MultiMap) Keys() []string

func (MultiMap) Put

func (h MultiMap) Put(key string, value []string)

func (MultiMap) Remove

func (h MultiMap) Remove(key string)

func (MultiMap) Values

func (h MultiMap) Values(key string) ([]string, bool)

Jump to

Keyboard shortcuts

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