From 6cfaca12896e19fc9a453be60ffa737e48c96d51 Mon Sep 17 00:00:00 2001 From: nopjmp Date: Mon, 22 May 2017 22:18:25 -0500 Subject: [PATCH] Add err check from GetTorrentById return in ApiViewHandler (#696) This should give a better response to API users for when something is not found. --- router/api_handler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/router/api_handler.go b/router/api_handler.go index 8c770aac..34eae5e0 100644 --- a/router/api_handler.go +++ b/router/api_handler.go @@ -92,6 +92,12 @@ func ApiViewHandler(w http.ResponseWriter, r *http.Request) { id := vars["id"] torrent, err := torrentService.GetTorrentById(id) + + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + b := torrent.ToJSON() w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(b)