🐛 Return server errors as 500 when marking a day fails

Marking a day answered every error except an invalid day key with 422,
including database errors. Only an invalid kind is a 422 now. Server
errors are logged with their cause and answered with a generic message
instead of the error text, which can contain SQL, and the timezone
lookup logs at warn before it falls back to UTC.
This commit is contained in:
2026-12-01 16:52:30 +01:00
parent 2bcf2d69a1
commit b41f83342c
4 changed files with 196 additions and 16 deletions
+6 -2
View File
@@ -229,10 +229,14 @@ func handleMarkDay(e *core.RequestEvent) error {
}
rec, err := MarkDay(e.App, e.Auth.Id, e.Request.PathValue("dayKey"), body.Kind, time.Now())
if err != nil {
if errors.Is(err, ErrInvalidDayKey) {
switch {
case errors.Is(err, ErrInvalidDayKey):
return writeError(e, http.StatusBadRequest, err)
case errors.Is(err, ErrInvalidKind):
return writeError(e, http.StatusUnprocessableEntity, err)
}
return writeError(e, http.StatusUnprocessableEntity, err)
// Everything else is a server failure, for example a database error.
return writeError(e, http.StatusInternalServerError, err)
}
return e.JSON(http.StatusOK, rec)
}