From 0a1aa869e4654092457f57b98fb5fdc582499f0a Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Mon, 12 Oct 2015 01:03:02 -0700 Subject: [PATCH] nicer 400 error page --- pages.go | 5 ++++- templates.go | 3 ++- templates/400.html | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 templates/400.html diff --git a/pages.go b/pages.go index 7481bc4..9d24bba 100644 --- a/pages.go +++ b/pages.go @@ -86,7 +86,10 @@ func oopsHandler(c web.C, w http.ResponseWriter, r *http.Request, rt RespType, m func badRequestHandler(c web.C, w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) - http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) + err := Templates["400.html"].ExecuteWriter(pongo2.Context{}, w) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } } func unauthorizedHandler(c web.C, w http.ResponseWriter, r *http.Request) { diff --git a/templates.go b/templates.go index 6575881..d8cd7bf 100644 --- a/templates.go +++ b/templates.go @@ -45,8 +45,9 @@ func populateTemplatesMap(tSet *pongo2.TemplateSet, tMap map[string]*pongo2.Temp "index.html", "paste.html", "API.html", - "404.html", + "400.html", "401.html", + "404.html", "oops.html", "display/audio.html", diff --git a/templates/400.html b/templates/400.html new file mode 100644 index 0000000..11f3e87 --- /dev/null +++ b/templates/400.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} +400 Bad Request +{% endblock %}