Skip to content

Commit b1f01ca

Browse files
refactor(ai-gateway): log drizzle cause on api_request_log insert failure (#2979)
* refactor(ai-gateway): streamline handleRequestLogging catch block * refactor(ai-gateway): log drizzle cause in handleRequestLogging catch * refactor(ai-gateway): log cause before error in handleRequestLogging --------- Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
1 parent 5b46022 commit b1f01ca

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

apps/web/src/lib/ai-gateway/handleRequestLogging.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,10 @@ export async function handleRequestLogging(params: {
6161
apiRequestLogId[0].id
6262
);
6363
} catch (e) {
64+
const cause = e instanceof Error ? e.cause : undefined;
6465
logExceptInTest(
65-
`[handleRequestLogging] failed to insert api_request_log (user=${user?.id}, status=${clonedResponse.status}, model=${model})`
66+
`[handleRequestLogging] failed to insert api_request_log (user=${user?.id}, status=${clonedResponse.status}, model=${model}) cause (truncated): ${String(cause).substring(0, 4000)} error (truncated): ${String(e).substring(0, 4000)}`
6667
);
67-
try {
68-
logExceptInTest(
69-
'[handleRequestLogging] error (truncated): ' + String(e).substring(0, 4000)
70-
);
71-
} catch {
72-
//ignore
73-
}
74-
try {
75-
logExceptInTest(
76-
'[handleRequestLogging] request (truncated): ' +
77-
JSON.stringify(request.body).substring(0, 4000)
78-
);
79-
} catch {
80-
//ignore
81-
}
82-
try {
83-
logExceptInTest(
84-
'[handleRequestLogging] response (truncated): ' + response?.substring(0, 4000)
85-
);
86-
} catch {
87-
//ignore
88-
}
8968
}
9069
});
9170
}

0 commit comments

Comments
 (0)