pages/api/trpc: track only server errors

This commit is contained in:
vchikalkin 2023-10-04 17:33:57 +03:00
parent 4dd4038091
commit 1d9c35b953

View File

@ -23,16 +23,17 @@ export default trpcNext.createNextApiHandler({
onError(opts) { onError(opts) {
const { error } = opts; const { error } = opts;
// send to bug reporting // send to bug reporting
withScope((scope) => { if (!['BAD_REQUEST', 'UNAUTHORIZED', 'FORBIDDEN'].includes(error.code))
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => { withScope((scope) => {
if (key !== 'req') { (Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
let extra = opts[key]; if (key !== 'req') {
if (key === 'input') extra = JSON.stringify(extra); let extra = opts[key];
scope.setExtra(key, extra); if (key === 'input') extra = JSON.stringify(extra);
} scope.setExtra(key, extra);
}
});
captureException(error);
}); });
captureException(error);
});
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error('Something went wrong', error); console.error('Something went wrong', error);
}, },