From d87bcee585883f22b2ca0b42db67bf815cc7c1fc Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 7 May 2026 00:20:15 +0300 Subject: Task 51: add API error helpers --- internal/api/handlers_file.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'internal/api/handlers_file.go') 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()}) -- cgit v1.2.3