- big big refactor.
This commit is contained in:
@@ -2,31 +2,43 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ErrorWithCode struct {
|
||||
level int
|
||||
str string
|
||||
code string
|
||||
intCode int
|
||||
}
|
||||
|
||||
func NewErrorCode(err, code string) *ErrorWithCode {
|
||||
return &ErrorWithCode{
|
||||
str: err,
|
||||
code: code,
|
||||
intCode: Str2Int(code),
|
||||
func NewErrorCode(err, code string, level ...int) *ErrorWithCode {
|
||||
retVal := &ErrorWithCode{
|
||||
str: err,
|
||||
code: code,
|
||||
}
|
||||
retVal.intCode, _ = strconv.Atoi(code)
|
||||
if len(level) > 0 {
|
||||
retVal.level = level[0]
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func NewErrorIntCode(err string, code int) *ErrorWithCode {
|
||||
return &ErrorWithCode{
|
||||
str: err,
|
||||
code: Int2Str(code),
|
||||
intCode: code,
|
||||
}
|
||||
func NewErrorIntCode(err string, code int, level ...int) *ErrorWithCode {
|
||||
return NewErrorCode(err, Int2Str(code), level...)
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) Error() string {
|
||||
return fmt.Sprintf("%s, code:%s", e.str, e.code)
|
||||
return fmt.Sprintf("level:%d, str:%s, code:%s", e.level, e.str, e.code)
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) String() string {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) Level() int {
|
||||
return e.level
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) Code() string {
|
||||
|
||||
Reference in New Issue
Block a user