-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
42 lines (33 loc) · 1 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
package render
import (
"fmt"
"html/template"
"net/http"
raven "github.com/getsentry/raven-go"
)
// ServeError function
func (a AppRenderer) ServeError(w http.ResponseWriter, req *http.Request, code int, err error, pageData interface{}) {
fmt.Println("serving error", err, code, pageData)
message := http.StatusText(code)
a.ErrorLogCallback(w, req, code, err)
http.Error(w, message, code)
// TODO panic wenn 500er? oder alle?
// panic(err)
}
// SentryLogger var for convenience
var SentryLogger = func(w http.ResponseWriter, req *http.Request, code int, err error) error {
// 401, 403, and 404 are not relevant for sentry logging
if code == http.StatusUnauthorized || code == http.StatusForbidden || code == http.StatusNotFound {
return nil
}
// build error artificially
if err == nil {
err = fmt.Errorf("HTTP error %d", code)
}
raven.SetHttpContext(raven.NewHttp(req))
raven.CaptureError(err, nil)
return nil
}
func getErrorTemplate(code int) (*template.Template, error) {
return nil, nil
}