From f108043068c8818c616cc2e760f53839d4ba9b01 Mon Sep 17 00:00:00 2001 From: RanXom Date: Mon, 13 Jul 2026 17:53:46 +0530 Subject: refactor(api): return structured error responses --- internal/api/photos.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'internal/api/photos.go') diff --git a/internal/api/photos.go b/internal/api/photos.go index 92c5c04..ca6b038 100644 --- a/internal/api/photos.go +++ b/internal/api/photos.go @@ -12,12 +12,12 @@ func (s *Server) handlePhotos( ) { photos, err := s.gallery.Gallery(r.Context()) if err != nil { - log.Printf("gallery: %v", err) + log.Printf("build gallery: %v", err) - http.Error( + writeError( w, - http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError, + "failed to build gallery", ) return } @@ -38,10 +38,12 @@ func (s *Server) handlePhotos( w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(response); err != nil { - http.Error( + log.Printf("encode photos response: %v", err) + + writeError( w, - http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError, + "failed to encode response", ) } } -- cgit v1.2.3