Skip to content

Commit

Permalink
fix rollbar filter by error class name
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Jan 9, 2025
1 parent 9654d8c commit 130fe7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/rollbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import config from 'configs/app';
import { ABSENT_PARAM_ERROR_MESSAGE } from 'lib/errors/throwOnAbsentParamError';
import { RESOURCE_LOAD_ERROR_MESSAGE } from 'lib/errors/throwOnResourceLoadError';

import { isBot, isHeadlessBrowser, isNextJsChunkError, getRequestInfo } from './utils';
import { isBot, isHeadlessBrowser, isNextJsChunkError, getRequestInfo, getExceptionClass } from './utils';

const feature = config.features.rollbar;

Expand Down Expand Up @@ -37,16 +37,23 @@ export const clientConfig: Configuration | undefined = feature.isEnabled ? {
return true;
}

const exceptionClass = getExceptionClass(item);
const IGNORED_EXCEPTION_CLASSES = [
// these are React errors - "NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node."
// they could be caused by browser extensions
// one of the examples - https://github.com/facebook/react/issues/11538
// we can ignore them for now
'NotFoundError',
];

if (exceptionClass && IGNORED_EXCEPTION_CLASSES.includes(exceptionClass)) {
return true;
}

return false;
},
hostSafeList: [ config.app.host ].filter(Boolean),
ignoredMessages: [
// these are React errors - "NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node."
// they could be caused by browser extensions
// one of the examples - https://github.com/facebook/react/issues/11538
// we can ignore them for now
'NotFoundError',

// these are errors that we throw on when make a call to the API
RESOURCE_LOAD_ERROR_MESSAGE,
ABSENT_PARAM_ERROR_MESSAGE,
Expand Down
7 changes: 7 additions & 0 deletions lib/rollbar/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _get from 'lodash/get';
import type { Dictionary } from 'rollbar';

export function isBot(userAgent: string | undefined) {
Expand Down Expand Up @@ -56,3 +57,9 @@ export function getRequestInfo(item: Dictionary): { url: string } | undefined {
}
return { url: item.request.url };
}

export function getExceptionClass(item: Dictionary) {
const exceptionClass = _get(item, 'body.trace.exception.class');

return typeof exceptionClass === 'string' ? exceptionClass : undefined;
}

0 comments on commit 130fe7a

Please sign in to comment.