Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
debug(sentry): listen to unhandledRejection
Browse files Browse the repository at this point in the history
  • Loading branch information
masonmcelvain committed Apr 3, 2023
1 parent 8b6529b commit 3e10ee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
19 changes: 6 additions & 13 deletions frontend/helpers/next-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,10 @@ export const withNoindexDevDomains: GetServerSidePropsMiddleware = (next) => {
};

export const withSentry: GetServerSidePropsMiddleware = (next) => {
return (context) => {
return new Promise((resolve, reject) => {
next(context).then(resolve, (e) => {
Sentry.captureException(e);
console.log('Reporting exception to sentry');
console.log(e);
setTimeout(() => {
console.log('delayed for a bit, now carrying on');
reject(e);
}, 1000);
});
});
};
process.on('unhandledRejection', (reason) => {
console.log('[Debug] Reporting exception to sentry', reason);
Sentry.captureException(reason);
console.log('[Debug] Reported to Sentry');
});
return next;
};
9 changes: 5 additions & 4 deletions frontend/pages/myPage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { wrapGetServerSidePropsWithSentry } from '@sentry/nextjs';
import { withSentry } from '@helpers/next-helpers';
import { GetServerSideProps } from 'next';

const MyComponent = () => {
return <h1>Hello World!</h1>;
};

export const getServerSideProps: GetServerSideProps =
wrapGetServerSidePropsWithSentry(async (context) => {
export const getServerSideProps: GetServerSideProps = withSentry(
async (context) => {
if (context.query.myParam === 'two') {
// only throw conditionally so that this page actually builds
Promise.reject(new Error("We don't like page two"));
}

return { props: {} };
}, '/myPage');
}
);

export default MyComponent;

0 comments on commit 3e10ee7

Please sign in to comment.