test-errcode
withchao 2 years ago
parent b8a1b6644b
commit 9bb30406ee

@ -1,10 +1,15 @@
package apiresp
import (
"OpenIM/pkg/errs"
"fmt"
)
type apiResponse struct {
ErrCode int `json:"errCode"`
ErrMsg string `json:"errMsg"`
ErrDlt string `json:"errDlt"`
Data any `json:"data"`
Data any `json:"data,omitempty"`
}
func apiSuccess(data any) *apiResponse {
@ -14,5 +19,13 @@ func apiSuccess(data any) *apiResponse {
}
func apiError(err error) *apiResponse {
return &apiResponse{ErrCode: 10000, ErrMsg: err.Error()}
unwrap := errs.Unwrap(err)
var dlt string
if unwrap != err {
dlt = fmt.Sprintf("%+v", dlt)
}
if codeErr, ok := unwrap.(errs.CodeError); ok {
return &apiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: dlt}
}
return &apiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error(), ErrDlt: dlt}
}

Loading…
Cancel
Save