You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.6 KiB
Go
68 lines
2.6 KiB
Go
package workerr
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go-micro.dev/v4/errors"
|
|
)
|
|
|
|
const serviceName = "joybuywork"
|
|
|
|
var (
|
|
OnceLockError = New("There is currently a request of the same type being processed", TooManyRequestsErrorCode) //单次操作
|
|
UnauthorizedError = New("Authorization Failed", http.StatusUnauthorized) //授权不成功
|
|
ServerError = InternalServerError("Data processing failed, please try again") //服务异常
|
|
BusyError = New("There are too many requests to process, please wait", BusyErrorCode) //服务繁忙,请重试
|
|
ExportError = New("The export task processing is abnormal, please export again", ExportErrorCode) //导出任务处理异常
|
|
S2SUnableToParseError = New("Please refer to the API integration documentation for relevant API integration methods", UnableToParseErrorCode) //无法解析数据
|
|
S2SNotSuccessError = New("Please confirm that the returned API response status code is correct.[data.code=200?]", S2SNotSuccessErrorCode) //s2s请求处理不成功
|
|
)
|
|
|
|
const (
|
|
MysqlErrorCode = 100000 //mysql错误
|
|
RedisErrorCode = 100001 //Redis错误
|
|
CacheErrorCode = 100002 //cache错误
|
|
BusyErrorCode = 100003 //服务繁忙错误
|
|
VerifyErrorCode = 100004 //参数错误
|
|
ExportErrorCode = 100005 //导出错误
|
|
TooManyRequestsErrorCode = 100006 //当前有一个同类型请求在处理
|
|
UnableToParseErrorCode = 100007 //无法被解析的数据
|
|
S2SNotSuccessErrorCode = 100008 //s2s无法成功
|
|
)
|
|
|
|
// MysqlError mysql 组件错误
|
|
func MysqlError(err error) error {
|
|
return New(err.Error(), MysqlErrorCode)
|
|
}
|
|
|
|
// RedisError redis 组件错误
|
|
func RedisError(err error) error {
|
|
return New(err.Error(), RedisErrorCode)
|
|
}
|
|
|
|
// CacheError cache 组件错误
|
|
func CacheError(err error) error {
|
|
return New(err.Error(), CacheErrorCode)
|
|
}
|
|
|
|
// VerifyError 参数错误
|
|
func VerifyError(tip string) error {
|
|
return New(tip, VerifyErrorCode)
|
|
}
|
|
|
|
func BadRequest(format string, a ...any) error {
|
|
return errors.BadRequest(serviceName, format, a...)
|
|
}
|
|
|
|
func InternalServerError(format string, a ...any) error {
|
|
return errors.InternalServerError(serviceName, format, a...)
|
|
}
|
|
|
|
func NotFound(format string, a ...any) error {
|
|
return errors.NotFound(serviceName, format, a...)
|
|
}
|
|
|
|
func New(detail string, code int32) error {
|
|
return errors.New(serviceName, detail, code)
|
|
}
|