Files
baseapi/utils/errorwithcode.go

55 lines
926 B
Go

package utils
import (
"fmt"
"strconv"
)
type ErrorWithCode struct {
level int
errMsg string
code string
intCode int
}
func NewErrorCode(errMsg, code string, level ...int) *ErrorWithCode {
retVal := &ErrorWithCode{
errMsg: errMsg,
code: code,
}
retVal.intCode, _ = strconv.Atoi(code)
if len(level) > 0 {
retVal.level = level[0]
}
return retVal
}
func NewErrorIntCode(errMsg string, code int, level ...int) *ErrorWithCode {
return NewErrorCode(errMsg, Int2Str(code), level...)
}
func (e *ErrorWithCode) Error() string {
return fmt.Sprintf("%s level:%d, code:%s", e.errMsg, e.level, e.code)
}
func (e *ErrorWithCode) String() string {
return e.Error()
}
func (e *ErrorWithCode) Level() int {
return e.level
}
func (e *ErrorWithCode) Code() string {
return e.code
}
func (e *ErrorWithCode) IntCode() int {
return e.intCode
}
func (e *ErrorWithCode) ErrMsg() string {
return e.errMsg
}