diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-12-26 02:24:06 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-12-26 02:34:19 +0100 |
commit | b91074ba9f523e3b2cbd31ed1915430c8c65502c (patch) | |
tree | 48cc65fb352fad1f128b51a2cba11e9e2bf0d48e /main.go | |
parent | bdad8bac2c904a439a5255358a8e9f90457bf663 (diff) | |
download | gallery-b91074ba9f523e3b2cbd31ed1915430c8c65502c.tar.gz gallery-b91074ba9f523e3b2cbd31ed1915430c8c65502c.tar.xz gallery-b91074ba9f523e3b2cbd31ed1915430c8c65502c.zip |
Indicate faulty requests better
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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 } |