sdk_LinkedMall-20260828161641/errors.go

72 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package sdk_LinkedMall
import "fmt"
// 业务错误码常量。
const (
// CodeShopTypeInvalid SKU 属于经销集采店铺,不可下单,应过滤该 SKU。
CodeShopTypeInvalid = "ShopTypeInvalid"
// CodeSkuPriceUnique SKU 价格非最新,需重新调用 RenderPurchaseOrder 获取最新价格后再下单。
CodeSkuPriceUnique = "SkuPriceUnique"
// CodePurchaseOrderNotFound 采购单号不存在,需核对入参 PurchaseOrderId。
CodePurchaseOrderNotFound = "PurchaseOrderNotFound"
// CodeRefundNumberMustLessThanOrder 退款数量大于订单商品数量,需修正退款数量。
CodeRefundNumberMustLessThanOrder = "RefundNumberMustLessThanOrder"
// CodeRefundAmountMustLessThanOrder 退款金额大于实付金额,需修正退款金额。
CodeRefundAmountMustLessThanOrder = "RefundAmountMustLessThanOrder"
// CodeHasNoPrivilege RAM 无接口权限,需检查 RAM 授权策略。
CodeHasNoPrivilege = "HasNoPrivilege"
// CodeOrderNotFound 订单 ID 不存在,需核对 OrderId。
CodeOrderNotFound = "OrderNotFound"
// CodeShopNotFind 店铺不存在,需核对 ShopId / PurchaserId。
CodeShopNotFind = "ShopNotFind"
// CodeSavePurchaseOrderError 保存采购单服务端异常,建议短间隔重试。
CodeSavePurchaseOrderError = "SavePurchaseOrderError"
// CodeOuterPurchaseOrderIdExist 外部业务单号重复,需更换 OuterPurchaseOrderId 并做好幂等。
CodeOuterPurchaseOrderIdExist = "OuterPurchaseOrderIdExist"
)
// APIError 表示业务侧返回的错误。
type APIError struct {
RequestId string
Code string
Message string
SubCode string
SubMessage string
}
// Error 实现 error 接口。
func (e *APIError) Error() string {
return fmt.Sprintf(
"linkedmall api error [requestId=%s code=%s subCode=%s]: %s %s",
e.RequestId, e.Code, e.SubCode, e.Message, e.SubMessage,
)
}
// CheckSuccess 校验响应是否业务成功。
//
// 返回 nil 表示 Success 为 true业务成功
// 否则返回 *APIError携带 Code / SubCode / SubMessage 便于定位原因。
func CheckSuccess(resp *CommonResponse) error {
if resp == nil {
return fmt.Errorf("linkedmall: empty response")
}
if resp.Success {
return nil
}
return &APIError{
RequestId: resp.RequestId,
Code: resp.Code,
Message: resp.Message,
SubCode: resp.SubCode,
SubMessage: resp.SubMessage,
}
}
// IsCode 判断响应是否命中指定错误码。
func IsCode(resp *CommonResponse, code string) bool {
return resp != nil && resp.Code == code
}
```
```go