From 2efe3ce53cebd373bf56ba7580bb63df16871bac Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 10 Nov 2019 11:29:20 -0500 Subject: Add correct errors for an nonexistent recipe id --- backend/main.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/main.go b/backend/main.go index 1ed188a..7376bd0 100644 --- a/backend/main.go +++ b/backend/main.go @@ -66,16 +66,27 @@ func SingleRecipe(w http.ResponseWriter, r *http.Request) { return } if r.Method == "GET" { + var status int + var msg string + recipe := RecipeFromId(recipe_id, db) if recipe == nil { - recipe = MakeRecipe() + status = http.StatusNotFound + msg = "Recipe not Found" + } else { + status = http.StatusOK + msg = "Successful" } + fmt.Println(status, msg, recipe) resp := APIResponseItem{ - Status: APIError{Code: 200, Msg: "Successful Request"}, + Status: APIError{Code: status, Msg: msg}, Data: make([]APIDataRecipe, 0), } - resp.Data = append(resp.Data, APIDataRecipe{recipe}) + + if status == http.StatusOK { + resp.Data = append(resp.Data, APIDataRecipe{recipe}) + } w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) -- cgit v1.1