2022-03-29 00:25:24 +00:00
|
|
|
import * as Sentry from "@sentry/nextjs";
|
2022-03-30 12:17:55 +00:00
|
|
|
import { NextMiddleware } from "next-api-middleware";
|
2022-03-29 00:25:24 +00:00
|
|
|
|
|
|
|
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);
|
2022-03-30 14:56:24 +00:00
|
|
|
console.log(err);
|
|
|
|
res.status(400).json({ message: "Something went wrong", error: err });
|
|
|
|
// res.json({ error: err });
|
2022-03-29 00:25:24 +00:00
|
|
|
}
|
|
|
|
};
|