🐛 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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user