-
Notifications
You must be signed in to change notification settings - Fork 0
/
routeError.go
53 lines (46 loc) · 1019 Bytes
/
routeError.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
package main
import (
"net/http"
"os"
rollbar "github.com/rollbar/rollbar-go"
)
type errorPageData struct {
Error string
RequestID string
Code int
}
var environment string
func init() {
environment = os.Getenv("ENVIRONMENT")
if environment == "production" {
rollbar.SetToken(os.Getenv("ROLLBAR_TOKEN"))
rollbar.SetEnvironment("production")
rollbar.SetCodeVersion(os.Getenv("GIT_REV"))
rollbar.SetServerRoot("github.com/wcalandro/prosu-twitter")
}
}
func routeError(w http.ResponseWriter, e string, err error, rID string, code int) {
data := errorPageData{
Error: e,
RequestID: rID,
Code: code,
}
if err.Error() != "User Error" {
if environment == "production" {
rollbar.Critical(err)
log.Critical(err.Error())
} else {
panic(err)
}
}
w.WriteHeader(code)
templates.ExecuteTemplate(w, "Error.html", data)
}
func captureError(err error) {
if environment == "production" {
rollbar.Critical(err)
log.Critical(err.Error())
} else {
panic(err)
}
}