[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
This commit is contained in:
tobi
2023-03-14 17:11:04 +01:00
committed by GitHub
parent d5529d6c9f
commit 196cd88b1c
17 changed files with 460 additions and 83 deletions

View File

@ -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)
}