🐛 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
+12 -4
View File
@@ -52,13 +52,21 @@ func Register(app core.App) {
})
}
// writeError answers err in the PocketBase error envelope plus the legacy "error"
// key, so that the old and the new client read the same message. A server error
// is logged with its cause and answered with a generic message, because the
// error text can contain SQL and other internals.
func writeError(e *core.RequestEvent, status int, err error) error {
// The body carries the PocketBase error envelope plus the legacy "error" key so
// that both the old and the new client read the unchanged message.
message := err.Error()
if status >= http.StatusInternalServerError {
e.App.Logger().Error("tracking request failed",
"method", e.Request.Method, "path", e.Request.URL.Path, "status", status, "error", err)
message = "internal server error"
}
return e.JSON(status, map[string]any{
"status": status,
"message": err.Error(),
"message": message,
"data": map[string]any{},
"error": err.Error(),
"error": message,
})
}