You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
6.1 KiB
150 lines
6.1 KiB
package common
|
|
|
|
// BusiError 业务错误类型
|
|
type BusiError struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
}
|
|
|
|
func (e *BusiError) Error() string {
|
|
return e.Msg
|
|
}
|
|
|
|
// 通用错误码
|
|
const (
|
|
Success = 200
|
|
ParamError = 400
|
|
Unauthorized = 401
|
|
Forbidden = 403
|
|
NotFound = 404
|
|
InternalError = 500
|
|
)
|
|
|
|
// 业务错误码(按模块分段)
|
|
const (
|
|
// 认证/用户 51xxx
|
|
UserPhoneExists = 51001
|
|
UserNotFound = 51002
|
|
PasswordError = 51003
|
|
TokenInvalid = 51004
|
|
TokenExpired = 51005
|
|
SmsCodeError = 51006
|
|
|
|
// 机巢 52xxx
|
|
DockNotFound = 52001
|
|
DockOffline = 52002
|
|
DockPending = 52003
|
|
DockExists = 52004
|
|
CommandNotFound = 52005
|
|
|
|
// 无人机 53xxx
|
|
DroneNotFound = 53001
|
|
|
|
// 告警 54xxx
|
|
AlarmNotFound = 54001
|
|
|
|
// 固件 55xxx
|
|
FirmwareNotFound = 55001
|
|
FirmwareVersionExist = 55002
|
|
FirmwareNotReleased = 55003
|
|
|
|
// 任务/航线 56xxx
|
|
TaskNotFound = 56001
|
|
RouteNotFound = 56002
|
|
TaskStateErr = 56003
|
|
ExecutionNotFound = 56004
|
|
|
|
// 媒体 57xxx
|
|
LiveNotFound = 57001
|
|
VideoNotFound = 57002
|
|
VideoUploading = 57003
|
|
LiveProviderDisabled = 57004
|
|
LiveProviderInvalid = 57005
|
|
LiveLeaseNotFound = 57006
|
|
|
|
// 计费 58xxx
|
|
TrafficNotEnough = 58001
|
|
OrderPaid = 58002
|
|
SimCardNotFound = 58003
|
|
OrderNotFound = 58004
|
|
CarrierUnavailable = 58005
|
|
PlatformTrafficExhausted = 58006
|
|
TrafficLedgerConflict = 58007
|
|
|
|
// 支付 59xxx
|
|
PaymentDisabled = 59001
|
|
PaymentOrderConflict = 59002
|
|
PaymentAlreadyPaid = 59003
|
|
PaymentTransactionNotFound = 59004
|
|
PendingOrderExists = 59005
|
|
OrderClosed = 59006
|
|
OrderNotCancellable = 59007
|
|
)
|
|
|
|
// 预定义的业务错误
|
|
var (
|
|
ErrSuccess = &BusiError{Code: Success, Msg: "成功"}
|
|
ErrParam = &BusiError{Code: ParamError, Msg: "参数错误"}
|
|
ErrUnauthorized = &BusiError{Code: Unauthorized, Msg: "未登录"}
|
|
ErrToken = &BusiError{Code: Unauthorized, Msg: "Token异常"}
|
|
SignOutToken = &BusiError{Code: Unauthorized, Msg: "Token已失效"}
|
|
ErrForbidden = &BusiError{Code: Forbidden, Msg: "无权限访问"}
|
|
ErrNotFound = &BusiError{Code: NotFound, Msg: "资源不存在"}
|
|
ErrInternal = &BusiError{Code: InternalError, Msg: "系统内部错误"}
|
|
|
|
ErrUserPhoneExists = &BusiError{Code: UserPhoneExists, Msg: "该手机号已注册"}
|
|
ErrUserNotFound = &BusiError{Code: UserNotFound, Msg: "用户不存在"}
|
|
ErrPasswordError = &BusiError{Code: PasswordError, Msg: "用户名或密码错误"}
|
|
ErrTokenInvalid = &BusiError{Code: TokenInvalid, Msg: "Token无效"}
|
|
ErrTokenExpired = &BusiError{Code: TokenExpired, Msg: "Token已过期"}
|
|
ErrSmsCodeError = &BusiError{Code: SmsCodeError, Msg: "短信验证码错误"}
|
|
|
|
ErrDockNotFound = &BusiError{Code: DockNotFound, Msg: "机巢不存在"}
|
|
ErrDockOffline = &BusiError{Code: DockOffline, Msg: "机巢离线"}
|
|
ErrDockPending = &BusiError{Code: DockPending, Msg: "机巢待登记"}
|
|
ErrDockExists = &BusiError{Code: DockExists, Msg: "该机巢编号已存在"}
|
|
ErrCommandNotFound = &BusiError{Code: CommandNotFound, Msg: "指令记录不存在"}
|
|
|
|
ErrDroneNotFound = &BusiError{Code: DroneNotFound, Msg: "无人机不存在"}
|
|
|
|
ErrAlarmNotFound = &BusiError{Code: AlarmNotFound, Msg: "告警不存在"}
|
|
|
|
ErrFirmwareNotFound = &BusiError{Code: FirmwareNotFound, Msg: "固件版本不存在"}
|
|
ErrFirmwareVersionExist = &BusiError{Code: FirmwareVersionExist, Msg: "该固件版本已存在"}
|
|
ErrFirmwareNotReleased = &BusiError{Code: FirmwareNotReleased, Msg: "固件未发布,无法下发升级"}
|
|
|
|
ErrTaskNotFound = &BusiError{Code: TaskNotFound, Msg: "任务不存在"}
|
|
ErrRouteNotFound = &BusiError{Code: RouteNotFound, Msg: "航线不存在"}
|
|
ErrTaskStateErr = &BusiError{Code: TaskStateErr, Msg: "任务状态不允许此操作"}
|
|
ErrExecutionNotFound = &BusiError{Code: ExecutionNotFound, Msg: "执行记录不存在"}
|
|
|
|
ErrLiveNotFound = &BusiError{Code: LiveNotFound, Msg: "直播会话不存在"}
|
|
ErrLiveProviderDisabled = &BusiError{Code: LiveProviderDisabled, Msg: "直播服务未配置"}
|
|
ErrLiveProviderInvalid = &BusiError{Code: LiveProviderInvalid, Msg: "直播服务配置无效"}
|
|
ErrLiveLeaseNotFound = &BusiError{Code: LiveLeaseNotFound, Msg: "直播观看租约不存在或已过期"}
|
|
ErrVideoNotFound = &BusiError{Code: VideoNotFound, Msg: "视频不存在"}
|
|
ErrVideoUploading = &BusiError{Code: VideoUploading, Msg: "视频上传中"}
|
|
|
|
ErrTrafficNotEnough = &BusiError{Code: TrafficNotEnough, Msg: "流量不足,请充值"}
|
|
ErrOrderPaid = &BusiError{Code: OrderPaid, Msg: "该订单已支付"}
|
|
ErrSimCardNotFound = &BusiError{Code: SimCardNotFound, Msg: "SIM卡不存在"}
|
|
ErrOrderNotFound = &BusiError{Code: OrderNotFound, Msg: "订单不存在"}
|
|
ErrCarrierUnavailable = &BusiError{Code: CarrierUnavailable, Msg: "运营商通道未接入"}
|
|
ErrPlatformTrafficExhausted = &BusiError{Code: PlatformTrafficExhausted, Msg: "资源异常,请联系管理员"}
|
|
ErrTrafficLedgerConflict = &BusiError{Code: TrafficLedgerConflict, Msg: "账务流水幂等冲突"}
|
|
ErrPaymentDisabled = &BusiError{Code: PaymentDisabled, Msg: "支付服务未配置"}
|
|
ErrPaymentOrderConflict = &BusiError{Code: PaymentOrderConflict, Msg: "支付订单幂等冲突"}
|
|
ErrPaymentAlreadyPaid = &BusiError{Code: PaymentAlreadyPaid, Msg: "订单已支付"}
|
|
ErrPaymentTransactionNotFound = &BusiError{Code: PaymentTransactionNotFound, Msg: "支付交易不存在"}
|
|
ErrPendingOrderExists = &BusiError{Code: PendingOrderExists, Msg: "存在未付款的订单,请前往订单页面付款或取消该订单后再创建新订单"}
|
|
ErrOrderClosed = &BusiError{Code: OrderClosed, Msg: "订单已关闭"}
|
|
ErrOrderNotCancellable = &BusiError{Code: OrderNotCancellable, Msg: "订单当前状态不允许取消"}
|
|
)
|
|
|
|
// NewBusiError 创建自定义业务错误
|
|
func NewBusiError(code int, msg string) *BusiError {
|
|
return &BusiError{
|
|
Code: code,
|
|
Msg: msg,
|
|
}
|
|
}
|
|
|