|
|
@ -1,10 +1,15 @@
|
|
|
|
package apiresp
|
|
|
|
package apiresp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
|
|
"OpenIM/pkg/errs"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type apiResponse struct {
|
|
|
|
type apiResponse struct {
|
|
|
|
ErrCode int `json:"errCode"`
|
|
|
|
ErrCode int `json:"errCode"`
|
|
|
|
ErrMsg string `json:"errMsg"`
|
|
|
|
ErrMsg string `json:"errMsg"`
|
|
|
|
ErrDlt string `json:"errDlt"`
|
|
|
|
ErrDlt string `json:"errDlt"`
|
|
|
|
Data any `json:"data"`
|
|
|
|
Data any `json:"data,omitempty"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func apiSuccess(data any) *apiResponse {
|
|
|
|
func apiSuccess(data any) *apiResponse {
|
|
|
@ -14,5 +19,13 @@ func apiSuccess(data any) *apiResponse {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func apiError(err error) *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}
|
|
|
|
}
|
|
|
|
}
|
|
|
|