Add method and pathname to ditto.http error

This commit is contained in:
Alex Gleason 2025-02-21 20:06:39 -06:00
parent 64e71b0ba8
commit 82446e3ef1
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 6 additions and 3 deletions

View file

@ -5,6 +5,9 @@ import { logi } from '@soapbox/logi';
import { errorJson } from '@/utils/log.ts'; import { errorJson } from '@/utils/log.ts';
export const errorHandler: ErrorHandler = (err, c) => { export const errorHandler: ErrorHandler = (err, c) => {
const { method } = c.req;
const { pathname } = new URL(c.req.url);
c.header('Cache-Control', 'no-store'); c.header('Cache-Control', 'no-store');
if (err instanceof HTTPException) { if (err instanceof HTTPException) {
@ -19,7 +22,7 @@ export const errorHandler: ErrorHandler = (err, c) => {
return c.json({ error: 'The server was unable to respond in a timely manner' }, 500); return c.json({ error: 'The server was unable to respond in a timely manner' }, 500);
} }
logi({ level: 'error', ns: 'ditto.http', msg: 'Unhandled error', error: errorJson(err) }); logi({ level: 'error', ns: 'ditto.http', msg: 'Unhandled error', method, pathname, error: errorJson(err) });
return c.json({ error: 'Something went wrong' }, 500); return c.json({ error: 'Something went wrong' }, 500);
}; };

View file

@ -12,8 +12,8 @@ export const logiMiddleware: MiddlewareHandler = async (c, next) => {
await next(); await next();
const end = new Date(); const end = new Date();
const delta = (end.getTime() - start.getTime()) / 1000; const duration = (end.getTime() - start.getTime()) / 1000;
const level = c.res.status >= 500 ? 'error' : 'info'; const level = c.res.status >= 500 ? 'error' : 'info';
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, delta }); logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, duration });
}; };