-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.go
More file actions
37 lines (34 loc) · 928 Bytes
/
http.go
File metadata and controls
37 lines (34 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"log"
"net/http"
"path/filepath"
"runtime"
)
func internalError(w http.ResponseWriter, r *http.Request, err error) {
data := map[string]interface{}{
"title": "Server Error | Zood",
"cssPath": "/css/server-error.css",
}
rsrcs := resourcesFromContext(r.Context())
emailer := sendEmailer(r.Context())
rsrcs.ExecuteTemplateCode("server-error.html", w, data, http.StatusInternalServerError)
if err != nil {
_, file, line, ok := runtime.Caller(1)
if !ok {
file = "???"
line = 0
}
file = filepath.Base(file)
log.Printf("%s:%d %v", file, line, err)
mailMsg := fmt.Sprintf("Buster Error\n%s:%d\n%v", file, line, err.Error())
mgErr := emailer.SendEmail("buster-errors@notifications.zood.xyz",
"arash@zood.xyz",
fmt.Sprintf("Buster Error: %s:%d", file, line),
mailMsg, nil)
if mgErr != nil {
log.Printf("Failed to email internal error: %v", mgErr)
}
}
}