You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/apiresp/resp.go

32 lines
670 B

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,omitempty"`
}
func apiSuccess(data any) *apiResponse {
return &apiResponse{
Data: data,
}
}
func apiError(err error) *apiResponse {
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}
}