Browse Source

添加新建错误的接口

yjp 2 years ago
parent
commit
65d6a10efc
1 changed files with 9 additions and 0 deletions
  1. 9 0
      errors.go

+ 9 - 0
errors.go

@@ -46,6 +46,10 @@ func TransferFromError(err error) *Error {
 	return NewUnknownError(err.Error())
 }
 
+func NewError(code uint32, message string) *Error {
+	return newError(code, message)
+}
+
 func NewUnknownError(message string) *Error {
 	return newError(ErrUnknownCode, message)
 }
@@ -125,6 +129,11 @@ func (err *Error) Format(s fmt.State, verb rune) {
 }
 
 func newError(code uint32, message string) *Error {
+	_, ok := codeMap[code]
+	if !ok {
+		code = ErrUnknownCode
+	}
+
 	return &Error{
 		code:         code,
 		message:      message,