You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/mw/specialerror/error.go

34 lines
628 B

package specialerror
import "OpenIM/pkg/errs"
var handlers []func(err error) errs.CodeError
func AddErrHandler(h func(err error) errs.CodeError) {
if h == nil {
panic("nil handler")
}
handlers = append(handlers, h)
}
func AddReplace(target error, codeErr errs.CodeError) {
AddErrHandler(func(err error) errs.CodeError {
if err == target {
return codeErr
}
return nil
})
}
func ErrCode(err error) errs.CodeError {
if codeErr, ok := err.(errs.CodeError); ok {
return codeErr
}
for i := 0; i < len(handlers); i++ {
if codeErr := handlers[i](err); codeErr != nil {
return codeErr
}
}
return nil
}