From b91074ba9f523e3b2cbd31ed1915430c8c65502c Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Tue, 26 Dec 2023 02:24:06 +0100 Subject: Indicate faulty requests better --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index c78f01e..04bc307 100644 --- a/main.go +++ b/main.go @@ -813,10 +813,14 @@ func handleAPIInfo(w http.ResponseWriter, r *http.Request) { var err error result.Width, result.Height, err = getImageDimensions(params.SHA1) - if err != nil { + if errors.Is(err, sql.ErrNoRows) { + http.Error(w, err.Error(), http.StatusNotFound) + return + } else if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } + result.Paths, err = getImagePaths(params.SHA1) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -920,7 +924,10 @@ func handleAPISimilar(w http.ResponseWriter, r *http.Request) { SELECT width, height, dhash, IFNULL(thumbw, 0), IFNULL(thumbh, 0) FROM image WHERE sha1 = ?`, params.SHA1).Scan(&width, &height, &dhash, &result.Info.ThumbW, &result.Info.ThumbH) - if err != nil { + if errors.Is(err, sql.ErrNoRows) { + http.Error(w, err.Error(), http.StatusNotFound) + return + } else if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } -- cgit v1.2.3-70-g09d2