mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Add prettier default error page.
This commit is contained in:
parent
fc216fb3de
commit
e72f87d801
2 changed files with 38 additions and 3 deletions
18
app/app.go
18
app/app.go
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -209,7 +208,19 @@ func handleAppError(e *AppError, w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
if e.Type != AppErrorTypeBadInput {
|
if e.Type != AppErrorTypeBadInput {
|
||||||
c.Errorf("%v", e.Error)
|
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 {
|
} else {
|
||||||
c.Infof("%v", e.Error)
|
c.Infof("%v", e.Error)
|
||||||
}
|
}
|
||||||
|
|
@ -249,10 +260,11 @@ type Template struct {
|
||||||
*template.Template
|
*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 {
|
if len(state) > 0 {
|
||||||
data["Flashes"] = state[0].Flashes()
|
data["Flashes"] = state[0].Flashes()
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
err := t.Execute(w, data)
|
err := t.Execute(w, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &AppError{
|
return &AppError{
|
||||||
|
|
|
||||||
23
app/templates/internal-error.html
Normal file
23
app/templates/internal-error.html
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{{define "title"}} Internal Error {{end}}
|
||||||
|
|
||||||
|
{{define "body"}}
|
||||||
|
|
||||||
|
{{if .ShowDetails}}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>HTTP status code:</b> {{.Error.Code}}<br>
|
||||||
|
<b>Error type:</b> {{.Error.Type}}<br>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Message:</b> {{.Error.Message}}<br>
|
||||||
|
<b>Error:</b> <pre>{{.Error.Error}}</pre>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
An internal error occured. The developer has been notified. Hopefully it'll
|
||||||
|
be fixed soon. You can also try checking the
|
||||||
|
<a href="https://github.com/mihaip/retrogit/issues">current issues list</a>.
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{end}}
|
||||||
Loading…
Reference in a new issue