summaryrefslogtreecommitdiff
path: root/internal/api/handlers_file.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-07 00:20:15 +0300
committerPaul Buetow <paul@buetow.org>2026-05-07 00:20:15 +0300
commitd87bcee585883f22b2ca0b42db67bf815cc7c1fc (patch)
treea879c345d3ebaecf526f12d7ad6cf97c6f7f4dba /internal/api/handlers_file.go
parente1bea8d74391a20201327299481550bf94766236 (diff)
Task 51: add API error helpers
Diffstat (limited to 'internal/api/handlers_file.go')
-rw-r--r--internal/api/handlers_file.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/internal/api/handlers_file.go b/internal/api/handlers_file.go
index 0638603..386ec6e 100644
--- a/internal/api/handlers_file.go
+++ b/internal/api/handlers_file.go
@@ -53,24 +53,24 @@ func (s *Server) handleDownload(w http.ResponseWriter, r *http.Request) {
}
id := pathID(r, "id")
if id == 0 {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid media id"})
+ badRequest(w, "invalid media id")
return
}
res, err := s.browseSvc.DownloadMedia(r.Context(), id, userIDFromContext(r))
if err != nil {
if errors.Is(err, service.ErrNotFound) {
- writeJSON(w, http.StatusNotFound, map[string]string{"error": "not found"})
+ notFound(w)
return
}
if errors.Is(err, service.ErrForbidden) {
- writeJSON(w, http.StatusForbidden, map[string]string{"error": "forbidden"})
+ forbidden(w, "forbidden")
return
}
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
if res == nil {
- writeJSON(w, http.StatusNotFound, map[string]string{"error": "not found"})
+ notFound(w)
return
}
s.serveFileResult(w, r, res, true)
@@ -90,16 +90,16 @@ func (s *Server) handleRegenThumbnail(w http.ResponseWriter, r *http.Request) {
}
id := pathID(r, "id")
if id == 0 {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid media id"})
+ badRequest(w, "invalid media id")
return
}
if err := s.writeSvc.RegenerateThumbnail(r.Context(), id, userIDFromContext(r)); err != nil {
if errors.Is(err, service.ErrNotFound) {
- writeJSON(w, http.StatusNotFound, map[string]string{"error": "not found"})
+ notFound(w)
return
}
if errors.Is(err, service.ErrForbidden) {
- writeJSON(w, http.StatusForbidden, map[string]string{"error": "forbidden"})
+ forbidden(w, "forbidden")
return
}
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})