commit 2f95a8e60c44fb0536c8c5327efeb399198a5efe
parent a3ba0658854d98257e7df6d872443fceeba88bda
Author: brookjeynes <me@brookjeynes.dev>
Date: Sun, 7 Jun 2026 18:17:37 +1000
fix: return server errors for db failures
Signed-off-by: brookjeynes <me@brookjeynes.dev>
Diffstat:
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/internal/server/new-album.go b/internal/server/new-album.go
@@ -125,7 +125,7 @@ func (ss *ServerState) NewAlbum(w http.ResponseWriter, r *http.Request) {
tx, err := ss.db.Begin()
if err != nil {
logger.Error("failed to begin db transaction", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add album.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add album.")
return
}
@@ -135,13 +135,13 @@ func (ss *ServerState) NewAlbum(w http.ResponseWriter, r *http.Request) {
logger.Error("failed to rollback db transaction", "err", rollbackErr)
}
logger.Error("failed to save new album into db", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add album.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add album.")
return
}
if err := tx.Commit(); err != nil {
logger.Error("failed to commit db transaction", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add album.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add album.")
return
}
diff --git a/internal/server/new-artist.go b/internal/server/new-artist.go
@@ -107,7 +107,7 @@ func (ss *ServerState) NewArtist(w http.ResponseWriter, r *http.Request) {
tx, err := ss.db.Begin()
if err != nil {
logger.Error("failed to begin db transaction", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add artist.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add artist.")
return
}
@@ -117,13 +117,13 @@ func (ss *ServerState) NewArtist(w http.ResponseWriter, r *http.Request) {
logger.Error("failed to rollback db transaction", "err", rollbackErr)
}
logger.Error("failed to save new artist into db", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add artist.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add artist.")
return
}
if err := tx.Commit(); err != nil {
logger.Error("failed to commit db transaction", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add artist.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add artist.")
return
}
diff --git a/internal/server/new-song.go b/internal/server/new-song.go
@@ -180,7 +180,7 @@ func (ss *ServerState) NewSong(w http.ResponseWriter, r *http.Request) {
tx, err := ss.db.Begin()
if err != nil {
logger.Error("failed to begin db transaction", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add song.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add song.")
return
}
@@ -190,13 +190,13 @@ func (ss *ServerState) NewSong(w http.ResponseWriter, r *http.Request) {
logger.Error("failed to rollback db transaction", "err", rollbackErr)
}
logger.Error("failed to save new song into db", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add song.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add song.")
return
}
if err := tx.Commit(); err != nil {
logger.Error("failed to commit db transaction", "err", err)
- htmx.HxError(w, http.StatusBadRequest, "Failed to add song.")
+ htmx.HxError(w, http.StatusInternalServerError, "Failed to add song.")
return
}