ghl-sentry
Version:
42 lines (41 loc) • 1.98 kB
JavaScript
import { ignoredErrorMaps } from '../ignoredStrings';
import { logDebuggingInfo } from '../common';
import { extractErrorMessageFromOrigException } from '../utils';
const ignoredErrors = ignoredErrorMaps.map((e) => ({ ...e, message: e.message.toLowerCase() }));
export const filterExemptedErrors = (event, hint) => {
try {
if (hint.originalException) {
const errorMessage = extractErrorMessageFromOrigException(hint.originalException);
const transformedHint = errorMessage.toString().toLowerCase();
let isFilteredError;
if (transformedHint.length) {
isFilteredError = ignoredErrors.some((e) => {
if (transformedHint.includes(e.message)) {
if (event?.tags?.companyId && e.companyIds?.includes(event.tags.companyId.toString())) {
// filtering specific error string based on list of companyIds to avoid logging into sentry
return true;
}
if (event?.tags?.locationId && e?.locationIds?.includes(event.tags.locationId.toString())) {
// filtering specific error string based on list of locationIds to avoid logging into sentry
return true;
}
// if both company iDs and location ids arrays are undefined, filter error string for all cases
if (!e.companyIds && !e.locationIds)
return true;
}
return false;
});
}
else {
isFilteredError = false;
}
if (isFilteredError) {
return true;
}
}
return false;
}
catch (err) {
logDebuggingInfo(`error while filtering errors: ${typeof err === 'string' ? err : JSON.stringify(err)}`);
}
};