mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 19:46:57 +08:00
api error
This commit is contained in:
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…
x
Reference in New Issue
Block a user