diff options
Diffstat (limited to 'internal/gtserror/error.go')
-rw-r--r-- | internal/gtserror/error.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/gtserror/error.go b/internal/gtserror/error.go index 981b987cb..56e546cf1 100644 --- a/internal/gtserror/error.go +++ b/internal/gtserror/error.go @@ -24,11 +24,18 @@ import ( // package private error key type. type errkey int +// ErrorType denotes the type of an error, if set. +type ErrorType string + const ( // error value keys. _ errkey = iota statusCodeKey notFoundKey + errorTypeKey + + // error types + TypeSMTP ErrorType = "smtp" // smtp (mail) error ) // StatusCode checks error for a stored status code value. For example @@ -57,3 +64,17 @@ func NotFound(err error) bool { func SetNotFound(err error) error { return errors.WithValue(err, notFoundKey, struct{}{}) } + +// Type checks error for a stored "type" value. For example +// an error from sending an email may set a value of "smtp" +// to indicate this was an SMTP error. +func Type(err error) ErrorType { + s, _ := errors.Value(err, errorTypeKey).(ErrorType) + return s +} + +// SetType will wrap the given error to store a "type" value, +// returning wrapped error. See Type() for example use-cases. +func SetType(err error, errType ErrorType) error { + return errors.WithValue(err, errorTypeKey, errType) +} |