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.
31 lines
651 B
31 lines
651 B
package apiresp
|
|
|
|
import (
|
|
"OpenIM/pkg/errs"
|
|
)
|
|
|
|
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 = err.Error()
|
|
}
|
|
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}
|
|
}
|