12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package gatecode
- import (
- "errors"
- "strings"
- "github.com/gogf/gf/v2/errors/gcode"
- "github.com/gogf/gf/v2/errors/gerror"
- )
- // ErrCode 表示错误码
- type ErrCode int
- //go:generate stringer -type ErrCode -linecomment
- // 定义错误码 *代码后错误注释,即返回用户的错误信息
- const (
- GLOBAL_SUCCESS ErrCode = 0 + iota
- )
- const (
- // GLOBAL_ERR_NIL 常用全局异常定义
- GLOBAL_ERR_ERR ErrCode = 1000 + iota //代理服务异常
- GLOBAL_ERR_SIGN //无效的签名
- GLOBAL_ERR_NOBALANCE //余额不足
- GLOBAL_ERR_OFTEN //系统繁忙,请稍候再试
- GLOBAL_ERR_NOTFIND //请求地址不存在
- GLOBAL_ERR_MISSPARAM //缺少参数:%s
- GLOBAL_ERR_INVALIDPARAM //无效参数:%s
- GLOBAL_ERR_SERVICE //远端服务异常
- )
- var globalErrMap = map[ErrCode]string{
- GLOBAL_SUCCESS: "请求成功",
- GLOBAL_ERR_ERR: "代理服务异常",
- GLOBAL_ERR_SIGN: "无效的签名",
- GLOBAL_ERR_NOBALANCE: "余额不足",
- GLOBAL_ERR_OFTEN: "系统繁忙,请稍候再试",
- GLOBAL_ERR_NOTFIND: "请求地址不存在",
- GLOBAL_ERR_MISSPARAM: "缺少参数:%s",
- GLOBAL_ERR_INVALIDPARAM: "无效参数:%s",
- GLOBAL_ERR_SERVICE: "远端服务异常",
- }
- func (i ErrCode) String() string {
- return globalErrMap[i]
- }
- // NewErrorWithCode 创建异常
- func NewErrorWithCode(err ErrCode, detail ...string) error {
- return gerror.WrapCode(gcode.New(int(err), err.String(), strings.Join(detail, ",")), errors.New(err.String()))
- }
|