github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/errors/base.go (about) 1 package errors 2 3 import ( 4 "fmt" 5 ) 6 7 type ApplicationError struct { 8 error 9 Code int `json:"code"` 10 Msg string `json:"msg"` 11 } 12 13 func NewApplicationError(code int, args ...interface{}) error { 14 rawmsg, ok := ApplicationErrorMap[code] 15 if ok { 16 return &ApplicationError{Code: code, Msg: fmt.Sprintf(rawmsg, args)} 17 } 18 return &ApplicationError{Code: code, Msg: "Unknown error"} 19 } 20 21 func (e *ApplicationError) Error() string { 22 //outmsg := utils.ObjectToJSONString(e) 23 //if outmsg != "" { 24 // return outmsg 25 //} 26 return e.Msg 27 }