From 81af8600766c2e4c174474869dbee2d9f66638cd Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sun, 25 Oct 2015 15:57:27 -0400 Subject: [PATCH] Add "not found" page --- construction.go | 11 +++++++++++ static/404.html | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 static/404.html diff --git a/construction.go b/construction.go index 41f10da..b21861d 100644 --- a/construction.go +++ b/construction.go @@ -3,6 +3,7 @@ package htmlhouse import ( "database/sql" "fmt" + "io/ioutil" "net/http" "regexp" "strings" @@ -90,6 +91,16 @@ func getHouse(app *app, w http.ResponseWriter, r *http.Request) error { // Fetch HTML html, err := getHouseHTML(app, houseID) if err != nil { + if err, ok := err.(impart.HTTPError); ok { + if err.Status == http.StatusNotFound { + page, err := ioutil.ReadFile(app.cfg.StaticDir + "/404.html") + if err != nil { + page = []byte("HTMLlot.") + } + fmt.Fprintf(w, "%s", page) + return nil + } + } return err } diff --git a/static/404.html b/static/404.html new file mode 100644 index 0000000..6f958ca --- /dev/null +++ b/static/404.html @@ -0,0 +1,40 @@ + + + + + HTMLlot + + + + + + + + + + +
+

HTMLlot

+ +
+ +
+

You arrive at a patch of dirt and detritus. Start building?

+
+ + + +