fix(handlers): Upload io.Copy error → 500 not 413 (B6), Me distinguishes no-rows from DB errors (B7)
This commit is contained in:
@@ -48,10 +48,15 @@ func (h *H) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *H) Me(c *gin.Context) {
|
||||
// B7: only no-rows → 401; other errors (PG down) go through dbErr → 503.
|
||||
u, qerr := h.st.GetUserByID(c, uid(c))
|
||||
if qerr != nil {
|
||||
if errors.Is(qerr, pgx.ErrNoRows) {
|
||||
err(c, http.StatusUnauthorized, "unauthorized", "no such user")
|
||||
return
|
||||
}
|
||||
dbErr(c, qerr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"id": u.ID, "username": u.Username, "role": u.Role})
|
||||
}
|
||||
|
||||
@@ -146,10 +146,17 @@ func (h *H) Upload(c *gin.Context) {
|
||||
err(c, http.StatusInternalServerError, "internal", "create tmp")
|
||||
return
|
||||
}
|
||||
// B6: only MaxBytesError returns 413; other io.Copy failures (disk full,
|
||||
// connection drop) return 500.
|
||||
if _, e := io.Copy(out, src); e != nil {
|
||||
out.Close()
|
||||
os.Remove(tmp)
|
||||
err(c, http.StatusRequestEntityTooLarge, "too_large", "upload failed")
|
||||
var mbe *http.MaxBytesError
|
||||
if errors.As(e, &mbe) {
|
||||
err(c, http.StatusRequestEntityTooLarge, "too_large", "file exceeds upload limit")
|
||||
return
|
||||
}
|
||||
err(c, http.StatusInternalServerError, "internal", "upload failed")
|
||||
return
|
||||
}
|
||||
out.Close()
|
||||
|
||||
Reference in New Issue
Block a user