mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add method and pathname to ditto.http error
This commit is contained in:
parent
64e71b0ba8
commit
82446e3ef1
2 changed files with 6 additions and 3 deletions
|
|
@ -5,6 +5,9 @@ import { logi } from '@soapbox/logi';
|
|||
import { errorJson } from '@/utils/log.ts';
|
||||
|
||||
export const errorHandler: ErrorHandler = (err, c) => {
|
||||
const { method } = c.req;
|
||||
const { pathname } = new URL(c.req.url);
|
||||
|
||||
c.header('Cache-Control', 'no-store');
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ export const logiMiddleware: MiddlewareHandler = async (c, next) => {
|
|||
await next();
|
||||
|
||||
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';
|
||||
|
||||
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 });
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue