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

31 lines
680 B

2 years ago
package apiresp
2 years ago
import (
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
2 years ago
)
2 years ago
type apiResponse struct {
2 years ago
ErrCode int `json:"errCode"`
ErrMsg string `json:"errMsg"`
ErrDlt string `json:"errDlt"`
2 years ago
Data any `json:"data,omitempty"`
2 years ago
}
2 years ago
func apiSuccess(data any) *apiResponse {
return &apiResponse{
2 years ago
Data: data,
}
}
2 years ago
func apiError(err error) *apiResponse {
2 years ago
unwrap := errs.Unwrap(err)
var dlt string
if unwrap != err {
2 years ago
dlt = err.Error()
2 years ago
}
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}
2 years ago
}