Reporting handled errors

In order to quickly understand and fix errors, it is often helpful to send additional diagnostic data which is specific to that error.

Sending JavaScript errors

The notifyException() function reports a JavaScript Error and can optionally attach additional information. The default form accepts:

error The JavaScript error which occurred
metadata (optional) A nested mapping of key/value pairs with additional diagnostic information
var error = new Error("Something broke!"),
    metadata = { "special info": { request_id: 12345 } };

Bugsnag.notifyException(error, metadata);

Use the expanded form to customize the error name or severity:

error The JavaScript error which occurred
name (optional) The name to assign to the error
metadata (optional) A nested mapping of key/value pairs with additional diagnostic information
severity (optional) The seriousness of the error, selected from the options info, warning and error, listed in order of increasing severity
var error = new Error("Something broke!"),
    metadata = { "special info": { request_id: 12345 } };

Bugsnag.notifyException(error, "Caching error", metadata, "warning");

Constructing custom errors

The notify() function requires a name and message which are used to construct and report a custom error and optionally attach additional information. The function accepts the following arguments:

name The name to assign to the error
message A message describing the error
metadata (optional) A nested mapping of key/value pairs with additional diagnostic information
severity (optional) The seriousness of the error, selected from the options info, warning and error, listed in order of increasing severity
var metadata = { "special info": { request_id: 12345 } };

Bugsnag.notify("Caching error", "Something broke!", metadata, "warning");

Customizing diagnostic data

The metadata argument to notify() and notifyException() creates a named section of diagnostic data using the top level key as the name and the key/value pairs as elements in the section. The following examples would create a section named “special info”, with elements named “request_id” and “message_id”:

// Sending a JavaScript error
Bugsnag.notifyException(new Error("Something broke!"), {
    "special info": {
        request_id: 12345,
        message_id: 854
    }
});
// Constructing a custom error
Bugsnag.notify("ErrorName", "Something broke!", {
    "special info": {
        request_id: 12345,
        message_id: 854
    }
});

Changing error grouping on the Bugsnag dashboard

By default, errors on your Bugsnag dashboard are grouped and considered related based on the file path and line number where it occurred. However, this may not be appropriate for every situation so the algorithm used can be customized by using the groupingHash metadata key.

For example, to group errors by the error message, set the groupingHash key to the error message in the additional information sent with an error:

Bugsnag.notifyException(e, {groupingHash: e.message});