mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
chore: add gperr.Unwrap method
This commit is contained in:
parent
8c6fe38edb
commit
be87d47ebb
1 changed files with 12 additions and 0 deletions
|
@ -41,6 +41,18 @@ func Wrap(err error, message ...string) Error {
|
|||
return &baseError{fmt.Errorf("%s: %w", message[0], err)}
|
||||
}
|
||||
|
||||
func Unwrap(err error) Error {
|
||||
//nolint:errorlint
|
||||
switch err := err.(type) {
|
||||
case interface{ Unwrap() []error }:
|
||||
return &nestedError{Extras: err.Unwrap()}
|
||||
case interface{ Unwrap() error }:
|
||||
return &baseError{err.Unwrap()}
|
||||
default:
|
||||
return &baseError{err}
|
||||
}
|
||||
}
|
||||
|
||||
func wrap(err error) Error {
|
||||
if err == nil {
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue