api error

This commit is contained in:
withchao 2023-03-23 09:48:11 +08:00
parent 486e69fd33
commit 1e683fcf95

View File

@ -42,7 +42,11 @@ func apiSuccess(data any) *apiResponse {
func apiError(err error) *apiResponse { func apiError(err error) *apiResponse {
unwrap := errs.Unwrap(err) unwrap := errs.Unwrap(err)
if codeErr, ok := unwrap.(errs.CodeError); ok { if codeErr, ok := unwrap.(errs.CodeError); ok {
return &apiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()} resp := apiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()}
if resp.ErrDlt == "" {
resp.ErrDlt = err.Error()
}
return &resp
} }
return &apiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error()} return &apiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error()}
} }