From 196cd88b1c7c44a337ca12f6a804f1bb7fa83c4a Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 14 Mar 2023 17:11:04 +0100 Subject: [feature] Allow admins to send test emails (#1620) * [feature] Allow admins to send test emails * implement unwrap on new error type * add + use gtserror types * GoToSocial Email Test -> GoToSocial Test Email * add + use getInstance db call * removed unused "unknown" error type --- internal/gtserror/error.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'internal/gtserror/error.go') 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) +} -- cgit v1.2.3