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) {
const { error } = opts;
// send to bug reporting
withScope((scope) => {
(Object.keys(opts) as Array<keyof typeof opts>).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<keyof typeof opts>).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);
},