From 1d9c35b953e0ec07aa0be307b1793091da9920aa Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 4 Oct 2023 17:33:57 +0300 Subject: [PATCH] pages/api/trpc: track only server errors --- apps/web/pages/api/trpc/[trpc].ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/web/pages/api/trpc/[trpc].ts b/apps/web/pages/api/trpc/[trpc].ts index d2f86de..3e78ce9 100644 --- a/apps/web/pages/api/trpc/[trpc].ts +++ b/apps/web/pages/api/trpc/[trpc].ts @@ -23,16 +23,17 @@ export default trpcNext.createNextApiHandler({ onError(opts) { const { error } = opts; // send to bug reporting - withScope((scope) => { - (Object.keys(opts) as Array).forEach((key) => { - if (key !== 'req') { - let extra = opts[key]; - if (key === 'input') extra = JSON.stringify(extra); - scope.setExtra(key, extra); - } + if (!['BAD_REQUEST', 'UNAUTHORIZED', 'FORBIDDEN'].includes(error.code)) + withScope((scope) => { + (Object.keys(opts) as Array).forEach((key) => { + if (key !== 'req') { + let extra = opts[key]; + if (key === 'input') extra = JSON.stringify(extra); + scope.setExtra(key, extra); + } + }); + captureException(error); }); - captureException(error); - }); // eslint-disable-next-line no-console console.error('Something went wrong', error); },