diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-19 16:51:48 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-19 17:05:59 +0200 |
| commit | 7260aa0cd70195a4679ca3c94204d9e618f947f2 (patch) | |
| tree | 9321f5f3d21b06d1ab6dd50420879bc5ea41f044 /types | |
| parent | f1a265190d8fd862bfff680fd0937a7f99759955 (diff) | |
Refactor: Make errors use the parent's error level
- All wrapped errors have to be created with types.NewWrappedError to
inherit the error level from the parent
- Or types.NewWrappedErrorLevel can be used which means a custom error
level is given. For example this is done with cancelling OAuth
- Client public errors are forwarded with handleError that also logs
it with the error's level
Diffstat (limited to 'types')
| -rw-r--r-- | types/error.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/types/error.go b/types/error.go index c49fba2..dc4b90e 100644 --- a/types/error.go +++ b/types/error.go @@ -27,6 +27,16 @@ type WrappedErrorMessage struct { Err error } +// NewWrappedError returns a WrappedErrorMessage and uses the error level from the parent +func NewWrappedError(message string, err error) *WrappedErrorMessage { + return &WrappedErrorMessage{Level: GetErrorLevel(err), Message: message, Err: err} +} + +// NewWrappedError returns a WrappedErrorMessage and uses the given error level from the parent +func NewWrappedErrorLevel(level ErrorLevel, message string, err error) *WrappedErrorMessage { + return &WrappedErrorMessage{Level: level, Message: message, Err: err} +} + func (e *WrappedErrorMessage) Unwrap() error { return e.Err } |
