Last active
January 14, 2023 01:20
-
-
Save brianr/7e5cebc520125dd470dc3a851d2d2ed9 to your computer and use it in GitHub Desktop.
rollbar.js - Ignore error types using checkIgnore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List of error class names to ignore | |
var ROLLBAR_IGNORED_CLASS_NAMES = ['ReferenceError']; | |
var _rollbarConfig = { | |
accessToken: '<your access token>', | |
captureUncaught: true, | |
captureUnhandledRejections: true, | |
payload: { | |
environment: '<your env name>' | |
}, | |
checkIgnore: function(isUncaught, args, payload) { | |
// payload is a json object with the data that is about to be sent to the Rollbar API. | |
// it has the structure as can be seen in the Rollbar UI for the occurrence. | |
// so, if you see occurrences in the Rollbar UI that you want to ignore, you can use the "raw json" view to see the | |
// structure, and then code against that in your checkIgnore function (like this example) to ignore them in the future. | |
// Here we have an example checkIgnore that will ignore when the class name is in our list of ignored class names | |
// (see ROLLBAR_IGNORED_CLASS_NAMES defined above). | |
// Return true to ignore. | |
var trace = payload.body.trace; | |
if (trace && trace.exception) { | |
if (ROLLBAR_IGNORED_CLASS_NAMES.indexOf(trace.exception.class) !== -1) { | |
// matches ignore list - return true to ignore | |
return true; | |
} | |
} | |
} | |
}; | |
// If you are using the standard rollbar.js snippet, the minified snippet code would go here. | |
// If you are using rollbar.js some other way (i.e. installed as a package), then you can configure as follows: | |
Rollbar.configure(_rollbarConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment