hono: catch HTTPException

This commit is contained in:
Alex Gleason 2024-04-30 12:46:29 -05:00
parent 0e6b4e8b45
commit 9ecf5db1b1
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,13 @@
import { NostrEvent, NStore } from '@nostrify/nostrify';
import { type Context, Env as HonoEnv, type Handler, Hono, Input as HonoInput, type MiddlewareHandler } from 'hono';
import {
type Context,
Env as HonoEnv,
type Handler,
Hono,
HTTPException,
Input as HonoInput,
type MiddlewareHandler,
} from 'hono';
import { cors, logger, serveStatic } from 'hono/middleware';
import { Conf } from '@/config.ts';
@ -103,9 +111,16 @@ const app = new Hono<AppEnv>();
if (Conf.sentryDsn) {
// @ts-ignore Mismatched hono types.
app.use('*', sentryMiddleware({ dsn: Conf.sentryDsn, ignoreErrors: 'HTTPException' }));
app.use('*', sentryMiddleware({ dsn: Conf.sentryDsn }));
}
app.onError((err) => {
if (err instanceof HTTPException) {
return err.getResponse();
}
throw err;
});
const debug = Debug('ditto:http');
app.use('/api/*', logger(debug));