diff --git a/packages/lib/server/defaultResponder.ts b/packages/lib/server/defaultResponder.ts index e044354e8d9ae3..86f283ac923771 100644 --- a/packages/lib/server/defaultResponder.ts +++ b/packages/lib/server/defaultResponder.ts @@ -19,6 +19,10 @@ export function defaultResponder(f: Handle) { } catch (err) { console.error(err); const error = getServerErrorFromUnknown(err); + // dynamic import of Sentry so it's only loaded when something goes wrong. + const captureException = (await import("@sentry/nextjs")).captureException; + captureException(err); + // return API route response return res .status(error.statusCode) .json({ message: error.message, url: error.url, method: error.method });