24 lines
389 B
Go
24 lines
389 B
Go
package responses
|
|
|
|
import "encoding/json"
|
|
|
|
type ErrorResponse struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
}
|
|
|
|
func (e *ErrorResponse) Error() string {
|
|
marshal, err := json.Marshal(e)
|
|
if err != nil {
|
|
return err.Error()
|
|
}
|
|
return string(marshal)
|
|
}
|
|
|
|
func NewErrorResp(code int, msg error) *ErrorResponse {
|
|
return &ErrorResponse{
|
|
Code: code,
|
|
Msg: msg.Error(),
|
|
}
|
|
}
|