Skip to content

Commit

Permalink
fix: Correct imports
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT committed Apr 28, 2021
1 parent 23f0d43 commit 0311c28
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/nextjs/src/utils/api-wrapping-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ function getOptions(loaders: Loader[]): LoaderOptions | undefined {
/** Wrap the given request handler for error-catching purposes */
function makeWrappedRequestHandler(origHandler: RequestHandler): WrappedRequestHandler {
// TODO are there any overloads we need to worry about?
return async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
try {
return await origHandler(req, res);
} catch (err) {
Sentry.captureException(err);
await Sentry.flush(2000);
return (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
return origHandler(req, res).catch(err => {
if (Sentry !== undefined) {
Sentry.withScope(scope => {
scope.addEventProcessor(event => Sentry.Handlers.parseRequest(event, req));
Sentry.captureException(err);
// eslint-disable-next-line no-console
});
Sentry.flush(2000).catch(() => {
// Never throws
});
} else {
// eslint-disable-next-line no-console
console.error(
"[Sentry] Please make sure to `import * as Sentry from '@sentry/nextjs';` in your file in order to capture errors",
);
}
throw err;
}
});
};
}

0 comments on commit 0311c28

Please sign in to comment.