fix: improve request logging (#1578)

* fix: improve request logging

* fix: also fix this while i'm here
This commit is contained in:
zk
2026-05-24 16:33:28 +01:00
committed by GitHub
parent dcb7c8d41b
commit 5abd6dde5b
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ function ParseGameChannels(raw: string | undefined): Partial<Record<GameGroup, s
try {
parsed = JSON.parse(raw);
} catch (err) {
throw new Error(`DISCORD_GAME_CHANNELS is not valid JSON: ${err}`);
throw new Error(`DISCORD_GAME_CHANNELS is not valid JSON: ${err}. Got ${raw}`);
}
if (!IsRecord(parsed)) {
@@ -53,10 +53,15 @@ export const RequestLoggerMiddleware: RequestHandler = (req, res, next) => {
return;
}
// @ts-expect-error set by {@link ResJsonInteceptor} when handlers use `res.json`
const responseBody: unknown | undefined = res.contentBody;
const contents = {
statusCode: res.statusCode,
requestQuery: req.query,
requestBody: safeBody,
// Explains validation/import failures etc.; otherwise logs only show the status code.
...(responseBody !== undefined && res.statusCode >= 400 && { responseBody }),
// This might actually be undefined, as it could be called in some weird scenarios?
from: (req[SYMBOL_TACHI_API_AUTH] as APITokenDocument | undefined)?.userID ?? null,