feat(errors): 统一 AppError(Code/Message/Cause/HTTPCode + Wrap %w + HTTPStatus + ToJSON {error:{code,message}})
This commit is contained in:
1 parent
ebeecc7a32
commit
7f7cb8fbf7
4 files changed
+420
No files matched your search
@@ -0,0 +1,19 @@
|
||||
package errors
|
||||
|
||||
import stdErrors "errors"
|
||||
|
||||
// IsAppError reports whether err is an *AppError or wraps one anywhere in its
|
||||
// chain. It uses errors.As under the hood, so wrapped causes are detected too.
|
||||
func IsAppError(err error) bool {
|
||||
var target *AppError
|
||||
return stdErrors.As(err, &target)
|
||||
}
|
||||
|
||||
// As extracts the first *AppError in err's chain, reporting whether one was
|
||||
// found. It mirrors errors.As but returns the typed error directly for
|
||||
// convenience. The returned error is the outermost AppError in the chain.
|
||||
func As(err error) (*AppError, bool) {
|
||||
var target *AppError
|
||||
ok := stdErrors.As(err, &target)
|
||||
return target, ok
|
||||
}
|
||||
Reference in new issue
Block a user