aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-26 02:24:06 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-26 02:34:19 +0100
commitb91074ba9f523e3b2cbd31ed1915430c8c65502c (patch)
tree48cc65fb352fad1f128b51a2cba11e9e2bf0d48e /main.go
parentbdad8bac2c904a439a5255358a8e9f90457bf663 (diff)
downloadgallery-b91074ba9f523e3b2cbd31ed1915430c8c65502c.tar.gz
gallery-b91074ba9f523e3b2cbd31ed1915430c8c65502c.tar.xz
gallery-b91074ba9f523e3b2cbd31ed1915430c8c65502c.zip
Indicate faulty requests better
Diffstat (limited to 'main.go')
-rw-r--r--main.go11
1 files changed, 9 insertions, 2 deletions
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
}