From e72f87d80114f495418a21e0f37ac098327bc827 Mon Sep 17 00:00:00 2001
From: Mihai Parparita
Date: Sun, 7 Dec 2014 14:58:46 -0800
Subject: [PATCH] Add prettier default error page.
---
app/app.go | 18 +++++++++++++++---
app/templates/internal-error.html | 23 +++++++++++++++++++++++
2 files changed, 38 insertions(+), 3 deletions(-)
create mode 100644 app/templates/internal-error.html
diff --git a/app/app.go b/app/app.go
index 8ca5ea9..91660d1 100644
--- a/app/app.go
+++ b/app/app.go
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"html/template"
- "io"
"io/ioutil"
"log"
"net/http"
@@ -209,7 +208,19 @@ func handleAppError(e *AppError, w http.ResponseWriter, r *http.Request) {
}
if e.Type != AppErrorTypeBadInput {
c.Errorf("%v", e.Error)
- sendAppErrorMail(e, r)
+ if !appengine.IsDevAppServer() {
+ sendAppErrorMail(e, r)
+ }
+ var data = map[string]interface{}{
+ "ShowDetails": appengine.IsDevAppServer(),
+ "Error": e,
+ }
+ w.WriteHeader(e.Code)
+ templateError := templates["internal-error"].Render(w, data)
+ if templateError != nil {
+ c.Errorf("Error %s rendering error template.", templateError.Error.Error())
+ }
+ return
} else {
c.Infof("%v", e.Error)
}
@@ -249,10 +260,11 @@ type Template struct {
*template.Template
}
-func (t *Template) Render(w io.Writer, data map[string]interface{}, state ...*AppSignedInState) *AppError {
+func (t *Template) Render(w http.ResponseWriter, data map[string]interface{}, state ...*AppSignedInState) *AppError {
if len(state) > 0 {
data["Flashes"] = state[0].Flashes()
}
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
err := t.Execute(w, data)
if err != nil {
return &AppError{
diff --git a/app/templates/internal-error.html b/app/templates/internal-error.html
new file mode 100644
index 0000000..039b98b
--- /dev/null
+++ b/app/templates/internal-error.html
@@ -0,0 +1,23 @@
+{{define "title"}} Internal Error {{end}}
+
+{{define "body"}}
+
+{{if .ShowDetails}}
+
+
+HTTP status code: {{.Error.Code}}
+Error type: {{.Error.Type}}
+
+
+
+Message: {{.Error.Message}}
+Error:
{{.Error.Error}}
+
+
+{{else}}
+ An internal error occured. The developer has been notified. Hopefully it'll
+ be fixed soon. You can also try checking the
+ current issues list.
+{{end}}
+
+{{end}}