fix(backend): dbErr 503 degradation for connection-class DB errors
This commit is contained in:
@@ -2,7 +2,6 @@ package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -22,8 +21,7 @@ func isUnique(e error) bool {
|
||||
func (a *api) listUsers(c *gin.Context) {
|
||||
users, e := a.st.ListUsers(c)
|
||||
if e != nil {
|
||||
log.Printf("db: %v", e)
|
||||
err(c, http.StatusInternalServerError, "internal", "db error")
|
||||
dbErr(c, e)
|
||||
return
|
||||
}
|
||||
out := make([]gin.H, 0, len(users))
|
||||
@@ -59,7 +57,7 @@ func (a *api) createUser(c *gin.Context) {
|
||||
err(c, http.StatusConflict, "exists", "username taken")
|
||||
return
|
||||
}
|
||||
err(c, http.StatusBadRequest, "bad_request", "invalid input")
|
||||
dbErr(c, e)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"id": id, "username": req.Username, "role": req.Role})
|
||||
@@ -81,7 +79,7 @@ func (a *api) deleteUser(c *gin.Context) {
|
||||
err(c, http.StatusNotFound, "not_found", "no such user")
|
||||
return
|
||||
}
|
||||
err(c, http.StatusInternalServerError, "internal", "db error")
|
||||
dbErr(c, e)
|
||||
return
|
||||
}
|
||||
if target.Role == "admin" {
|
||||
@@ -92,7 +90,7 @@ func (a *api) deleteUser(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
if e := a.st.DeleteUser(c, id); e != nil {
|
||||
err(c, http.StatusInternalServerError, "internal", "db error")
|
||||
dbErr(c, e)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
|
||||
Reference in New Issue
Block a user