错误返回
This commit is contained in:
parent
12f37a9b43
commit
3dd9a9f41a
|
@ -0,0 +1,32 @@
|
|||
package result
|
||||
|
||||
const defaultCode = 1001
|
||||
|
||||
type CodeError struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
type CodeErrorResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func NewCodeError(code int, msg string) error {
|
||||
return &CodeError{Code: code, Msg: msg}
|
||||
}
|
||||
|
||||
func NewDefaultError(msg string) error {
|
||||
return NewCodeError(defaultCode, msg)
|
||||
}
|
||||
|
||||
func (e *CodeError) Error() string {
|
||||
return e.Msg
|
||||
}
|
||||
|
||||
func (e *CodeError) Data() *CodeErrorResponse {
|
||||
return &CodeErrorResponse{
|
||||
Code: e.Code,
|
||||
Msg: e.Msg,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue