|
| 1 | +import "./instrument"; |
| 2 | + |
1 | 3 | import { dirname } from "node:path"; |
2 | 4 | import { fileURLToPath, pathToFileURL } from "node:url"; |
3 | 5 | import { serve } from "@hono/node-server"; |
4 | 6 | import { createNodeWebSocket } from "@hono/node-ws"; |
| 7 | +import * as Sentry from "@sentry/node"; |
5 | 8 | import type { Session, User } from "better-auth/types"; |
6 | 9 | import { eq, sql } from "drizzle-orm"; |
7 | 10 | import { migrate } from "drizzle-orm/node-postgres/migrator"; |
@@ -148,6 +151,19 @@ function buildContentDisposition(filename: string, inline: boolean) { |
148 | 151 |
|
149 | 152 | export function createApp() { |
150 | 153 | const app = new Hono<AppVariables>(); |
| 154 | + |
| 155 | + app.onError((err, c) => { |
| 156 | + if (err instanceof HTTPException) { |
| 157 | + // expected errors (401/404/...) are not reported; real failures are |
| 158 | + if (err.status >= 500) { |
| 159 | + Sentry.captureException(err); |
| 160 | + } |
| 161 | + return err.getResponse(); |
| 162 | + } |
| 163 | + |
| 164 | + Sentry.captureException(err); |
| 165 | + return c.json({ message: "Internal Server Error" }, 500); |
| 166 | + }); |
151 | 167 | const nodeWs = createNodeWebSocket({ app }); |
152 | 168 | const { upgradeWebSocket, injectWebSocket } = nodeWs; |
153 | 169 | const corsOriginSource = [ |
|
0 commit comments