diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-11-10 11:29:20 -0500 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-11-10 11:29:20 -0500 |
commit | 2efe3ce53cebd373bf56ba7580bb63df16871bac (patch) | |
tree | a6b4f5e19585297beff6a92653912b475cae6cd5 /backend/main.go | |
parent | 4f408d2b9521a2e0ff22495f6a6a6646e5a3135d (diff) |
Add correct errors for an nonexistent recipe id
Diffstat (limited to 'backend/main.go')
-rw-r--r-- | backend/main.go | 17 |
1 files 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) |