jys 849af4d77f 增加为错误增加堆栈的函数 | 1 year ago | |
---|---|---|
.gitignore | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
center.go | 1 year ago | |
center_test.go | 1 year ago | |
code.go | 1 year ago | |
code_test.go | 1 year ago | |
compatible.go | 1 year ago | |
errors.go | 1 year ago | |
errors_test.go | 1 year ago | |
go.mod | 1 year ago | |
go.sum | 1 year ago | |
option.go | 1 year ago | |
option_test.go | 1 year ago | |
public.go | 1 year ago | |
public_test.go | 1 year ago | |
stack.go | 1 year ago |
方是错误封装
package main
import (
"fmt"
"git.sxidc.com/service-supports/fserr/v2alpha"
)
const (
ErrProjectNotExist = iota + 201
)
func init() {
// 设置服务码
fserr.SetAppCode(10)
// fserr包内置错误码
fserr.NewOK(fserr.ErrDb, "处理失败,请联系开发人员")
// 业务模块错误
fserr.NewOK(ErrProjectNotExist, "项目不存在")
}
func Add() error {
return fserr.WithCode(nil, ErrProjectNotExist)
}
func main() {
err := Add()
if err != nil {
fmt.Printf("%+v\n", fserr.ParseCode(err))
return
}
}