-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
86 lines (69 loc) · 1.69 KB
/
error.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"github.com/anton2920/gofa/errors"
"github.com/anton2920/gofa/log"
"github.com/anton2920/gofa/net/http"
"github.com/anton2920/gofa/trace"
)
func DisplayErrorMessage(w *http.Response, l Language, message string) {
if message != "" {
w.WriteString(`<div><p>`)
w.WriteString(Ls(l, "Error"))
w.WriteString(`: `)
//w.WriteHTMLString(message)
w.WriteHTMLString(Ls(l, message))
w.WriteString(`.</p></div>`)
}
}
func DisplayError(w *http.Response, l Language, err error) {
var message string
if err != nil {
if httpError, ok := err.(http.Error); ok {
w.StatusCode = httpError.StatusCode
message = httpError.DisplayMessage
} else if _, ok := err.(errors.Panic); ok {
w.StatusCode = http.ServerError(nil).StatusCode
message = http.ServerError(nil).DisplayMessage
} else {
log.Panicf("Unsupported error type %T", err)
}
if Debug {
message = err.Error()
}
}
DisplayErrorMessage(w, l, message)
}
func ErrorPageHandler(w *http.Response, r *http.Request, l Language, err error) {
defer trace.End(trace.Begin(""))
const width = WidthMedium
w.Headers.Set("Connection", "close")
w.Body = w.Body[:0]
session, _ := GetSessionFromRequest(r)
DisplayHTMLStart(w)
DisplayHeadStart(w)
{
w.WriteString(`<title>`)
w.WriteString(Ls(l, "Error"))
w.WriteString(`</title>`)
}
DisplayHeadEnd(w)
DisplayBodyStart(w)
{
DisplayHeader(w, l)
if session != nil {
DisplaySidebar(w, l, session)
}
DisplayMainStart(w)
DisplayPageStart(w, width)
{
w.WriteString(`<h2>`)
w.WriteString(Ls(l, "Error"))
w.WriteString(`</h2>`)
DisplayError(w, l, err)
}
DisplayPageEnd(w)
DisplayMainEnd(w)
}
DisplayBodyEnd(w)
DisplayHTMLEnd(w)
}