jys d030872409 错误码冲突时panic报错 | 1 year ago | |
---|---|---|
v2alpha | 1 year ago | |
.gitignore | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
errors.go | 1 year ago | |
errors_test.go | 1 year ago | |
go.mod | 1 year ago | |
go.sum | 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
}
}