summaryrefslogtreecommitdiff
path: root/internal/gtserror
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-03-14 17:11:04 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-14 16:11:04 +0000
commit196cd88b1c7c44a337ca12f6a804f1bb7fa83c4a (patch)
tree9607d95b3f4f55a1ebfeded2f7aa9a3c8866bd0a /internal/gtserror
parent[chore] fix + update swagger docs (#1622) (diff)
downloadgotosocial-196cd88b1c7c44a337ca12f6a804f1bb7fa83c4a.tar.xz
[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
Diffstat (limited to 'internal/gtserror')
-rw-r--r--internal/gtserror/error.go21
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)
+}