mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-14 01:59:05 +03:00
fix: improve request logging (#1578)
* fix: improve request logging * fix: also fix this while i'm here
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user