From 820d7a5c633c48e672f3d73328c4c368b06086be Mon Sep 17 00:00:00 2001 From: yanweidong Date: Sat, 4 Oct 2025 20:21:45 +0800 Subject: [PATCH] fix errcode --- errcode/errcode.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/errcode/errcode.go b/errcode/errcode.go index 23e7882..3eedd97 100644 --- a/errcode/errcode.go +++ b/errcode/errcode.go @@ -11,6 +11,7 @@ import ( // HTTP请求头相关错误码,起始码:1000 var ( + AllErrors = make(map[int]string) ErrHeaderRequestId = NewError(1001, "Header Request-Id Not Found") // 请求ID头缺失 ErrHeaderAuthorization = NewError(1002, "Header Authorization Not Found") // 授权头缺失 ErrHeaderSecretKey = NewError(1003, "Header Secret-Key Not Found") // 密钥头缺失 @@ -81,6 +82,7 @@ var ( // code: 错误码 // msg: 错误消息 func NewError(code int, msg string) error { + AllErrors[code] = msg return status.New(codes.Code(code), msg).Err() } @@ -88,6 +90,7 @@ func NewError(code int, msg string) error { // code: 错误码 // msg: 错误消息 func ErrFatal(code int, msg string) error { + AllErrors[code] = msg return status.New(codes.Code(code), msg).Err() } @@ -95,5 +98,6 @@ func ErrFatal(code int, msg string) error { // code: 错误码 // msg: 错误消息,会自动转换为大写 func ErrNotFound(code int, msg string) error { + AllErrors[code] = strings.ToUpper(msg) return status.New(codes.Code(code), strings.ToUpper(msg)).Err() }