-
Notifications
You must be signed in to change notification settings - Fork 8
/
exception.go
63 lines (51 loc) · 1.17 KB
/
exception.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
package gottp
import (
"bytes"
"html/template"
utils "gopkg.in/simversity/gottp.v3/utils"
)
const errorExtra = `
Host: {{.Host}}
Method: {{.Method}}
Protocol: {{.Protocol}}
RemoteIP: {{.RemoteIP}}
URI: {{.URI}}
Referer: {{.Referer}}
Arguments: {{.Arguments}}
`
type ErrorStack struct {
Host string
Method string
Protocol string
RemoteIP string
URI string
Referer string
Arguments string
}
func getTracerExtra(req *Request) func(reason string) string {
return func(reason string) string {
e := HttpError{500, "Internal Server Error: " + reason}
req.Raise(e)
if req == nil {
return ""
}
var referrer string
if len(req.Request.Header["Referer"]) > 0 {
referrer = req.Request.Header["Referer"][0]
}
params := string(utils.Encoder(req.GetArguments()))
stack := ErrorStack{
Host: req.Request.Host,
Method: req.Request.Method,
Protocol: req.Request.Proto,
RemoteIP: req.Request.RemoteAddr,
URI: req.Request.URL.Path,
Referer: referrer,
Arguments: params,
}
var doc bytes.Buffer
t := template.Must(template.New("error_email").Parse(errorExtra))
t.Execute(&doc, stack)
return doc.String()
}
}