diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 17:53:46 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 17:53:46 +0530 |
| commit | f108043068c8818c616cc2e760f53839d4ba9b01 (patch) | |
| tree | 01dce4dbdfd531f3eb60c920c3232c8bbafd43f4 /internal/api/photos.go | |
| parent | d87995c3629cac4671b05073915214f45d0c7112 (diff) | |
| download | galleryd-f108043068c8818c616cc2e760f53839d4ba9b01.tar.xz galleryd-f108043068c8818c616cc2e760f53839d4ba9b01.zip | |
refactor(api): return structured error responses
Diffstat (limited to 'internal/api/photos.go')
| -rw-r--r-- | internal/api/photos.go | 12 |
1 files changed, 7 insertions, 5 deletions
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", ) } } |