interview-one-stop-server/util/ierrors/error.go

61 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package ierrors
import "fmt"
type ErrNumber struct {
Code int
Message string
}
func (err ErrNumber) Error() string {
return err.Message
}
type OneStopErr struct {
ErrNumber
Errord error // 保存内部错误信息
}
func (err *OneStopErr) Error() string {
return fmt.Sprintf("OneStop - code: %d, message: %s, error: %s", err.Code, err.Message, err.Errord)
}
func NewOneStopErr(errN ErrNumber, err error) OneStopErr {
return OneStopErr{
ErrNumber: errN,
Errord: err,
}
}
var OneStopSuccess = NewOneStopErr(Success, nil)
//错误码一共四位,一二位为功能,三四位为具体错误
var (
Success = ErrNumber{
Code: 0,
Message: "SUCCEED",
}
/*** 公共错误码一二位为10 ***/
ErrJsonParseFailed = ErrNumber{
Code: 1000,
Message: "JSON 转换失败",
}
ErrHttpBodyReadFailed = ErrNumber{
Code: 1001,
Message: "请求body获取失败",
}
ErrHttpDbOperateFailed = ErrNumber{
Code: 1002,
Message: "数据库操作异常",
}
ErrHttpParamNotValid = ErrNumber{
Code: 1003,
Message: "入参不符合要求",
}
)