cal.pub0.org/lib/helpers/captureErrors.ts

15 lines
404 B
TypeScript
Raw Normal View History

import * as Sentry from "@sentry/nextjs";
2022-03-30 12:17:55 +00:00
import { NextMiddleware } from "next-api-middleware";
export const captureErrors: NextMiddleware = async (_req, res, next) => {
try {
// Catch any errors that are thrown in remaining
// middleware and the API route handler
await next();
} catch (err) {
2022-03-30 12:17:55 +00:00
Sentry.captureException(err);
res.status(500);
res.json({ error: err });
}
};