From 26c6e8e8fb3a37344fba8438af54e2947a5e5b0b Mon Sep 17 00:00:00 2001 From: clsr Date: Mon, 20 Jun 2016 15:33:30 +0200 Subject: Handle empty /static/grill dirs --- website.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website.go b/website.go index be962e6..7cc32c1 100644 --- a/website.go +++ b/website.go @@ -100,7 +100,9 @@ func handleGrill(w http.ResponseWriter, r *http.Request) { grills, err := ioutil.ReadDir("static/grill/") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) - return + } else if len(grills) == 0 { + http.Error(w, "files not found", http.StatusNotFound) + } else { + http.Redirect(w, r, "/static/grill/"+grills[rand.Intn(len(grills))].Name(), http.StatusFound) } - http.Redirect(w, r, "/static/grill/"+grills[rand.Intn(len(grills))].Name(), http.StatusFound) } -- cgit