aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2025-07-27 17:14:03 +0200
committerThomas Voss <mail@thomasvoss.com> 2025-07-27 17:14:03 +0200
commitc9b91a8bb1d9249c0617bfa52f0129a9d5d123c5 (patch)
treec075ceab4f55f22a9752a79f9a94616bee818152
parentc8bce099a30ac5faaee19a74799b121428fc2f79 (diff)
Swap out email.ServerError() for email.Send()
-rw-r--r--src/email/email.go14
-rw-r--r--src/http.go6
2 files changed, 12 insertions, 8 deletions
diff --git a/src/email/email.go b/src/email/email.go
index 33b30e0..a1f7f0b 100644
--- a/src/email/email.go
+++ b/src/email/email.go
@@ -6,6 +6,8 @@ import (
"crypto/tls"
"fmt"
"math/rand/v2"
+ "log"
+ "errors"
"net/smtp"
"strconv"
"time"
@@ -29,14 +31,20 @@ Message-ID: <%s>
%s`
-func ServerError(fault error) error {
+func Send(subject, body string) {
+ if err := send(subject, body); err != nil {
+ log.Print(err)
+ }
+}
+
+func send(subject, body string) error {
if Config.Disabled {
- return fault
+ return errors.New(body)
}
msgid := strconv.FormatInt(rand.Int64(), 10) + "@" + Config.Host
msg := fmt.Sprintf(emailTemplate, Config.FromAddr, Config.ToAddr,
- "Error Report", time.Now().Format(time.RFC1123Z), msgid, fault)
+ subject, time.Now().Format(time.RFC1123Z), msgid, body)
tlsConfig := &tls.Config{
InsecureSkipVerify: false,
diff --git a/src/http.go b/src/http.go
index b785bca..b0d5bcd 100644
--- a/src/http.go
+++ b/src/http.go
@@ -179,11 +179,7 @@ func setUserLanguage(w http.ResponseWriter, r *http.Request) {
func throwError(status int, err error, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(status)
- go func() {
- if err := email.ServerError(err); err != nil {
- log.Println(err)
- }
- }()
+ go email.Send("Server Error", err.Error())
errorTmpl.Execute(w, struct {
Code int
Msg string