fix(backend): dbErr 503 degradation for connection-class DB errors

This commit is contained in:
2026-09-06 19:53:19 +08:00
parent 04095b5438
commit a11bf28155
8 changed files with 61 additions and 18 deletions
+3 -3
View File
@@ -24,7 +24,7 @@ func (a *api) getBookRow(c *gin.Context, id int64) (store.Book, bool) {
err(c, http.StatusNotFound, "not_found", "no such book")
return store.Book{}, false
}
err(c, http.StatusInternalServerError, "internal", "db error")
dbErr(c, e)
return store.Book{}, false
}
return b, true
@@ -87,7 +87,7 @@ func (a *api) listBooks(c *gin.Context) {
libID, _ := strconv.ParseInt(c.Query("library"), 10, 64)
views, e := a.st.ListBooks(c, libID, c.Query("q"), c.Query("prefix"), uid(c))
if e != nil {
err(c, http.StatusInternalServerError, "internal", "db error")
dbErr(c, e)
return
}
out := make([]gin.H, 0, len(views))
@@ -133,7 +133,7 @@ func (a *api) deleteBook(c *gin.Context) {
os.RemoveAll(bookfile.CoverDir(a.cfg.CacheDir, key))
os.RemoveAll(bookfile.PagesDir(a.cfg.CacheDir, key))
if e := a.st.DeleteBook(c, b.ID); e != nil {
err(c, http.StatusInternalServerError, "internal", "db error")
dbErr(c, e)
return
}
c.Status(http.StatusNoContent)