From 983703efdaf90b3ed4a78f2401201d69733044fd Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Tue, 21 Jul 2026 14:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6:=20ymt=5Fv?= =?UTF-8?q?3=5Fapi/errors.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ymt_v3_api/errors.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ymt_v3_api/errors.go diff --git a/ymt_v3_api/errors.go b/ymt_v3_api/errors.go new file mode 100644 index 0000000..f125e81 --- /dev/null +++ b/ymt_v3_api/errors.go @@ -0,0 +1,42 @@ +package ymt_v3_api + +import "fmt" + +// APIError 表示 API 返回的错误信息。 +type APIError struct { + Code int `json:"code"` + Message string `json:"message"` + Reason string `json:"reason,omitempty"` +} + +func (e *APIError) Error() string { + if e.Reason != "" { + return fmt.Sprintf("API error [%d]: %s (reason: %s)", e.Code, e.Message, e.Reason) + } + return fmt.Sprintf("API error [%d]: %s", e.Code, e.Message) +} + +// 公共错误码常量 +const ( + ErrCodeSystemError = 500 + ErrCodeInvalidPayload = 400 + ErrCodeMissingParam = 400 + ErrCodeInvalidTimestamp = 400 + ErrCodeDecryptFailed = 400 + ErrCodeAppNotFound = 401 + ErrCodeInvalidSignature = 401 + ErrCodeExpiredTimestamp = 401 + ErrCodeDuplicateRequest = 429 + ErrCodeActivityNotAuth = 401 + ErrCodeMerchantNotExist = 401 + ErrCodeMerchantNotAuth = 401 + ErrCodeMerchantAppIncomplete = 401 + ErrCodeMerchantAppNotAuth = 401 + ErrCodeActivityExpire = 403 + ErrCodeActivityOutOfStock = 403 + ErrCodeActivityNotExist = 404 + ErrCodeMerchantOrderNotExist = 404 + ErrCodeKeyNotExist = 404 + ErrCodeParamFail = 400 + ErrCodeParamDecryptFail = 400 +) \ No newline at end of file