noticeError

newrelic.noticeError(error object $error)
Identifies a browser error without disrupting your app's operations.

Requirements

newrelic.noticeError() requires agent version nr-499 or higher.

NREUM.noticeError() requires agent version nr-411 or higher.

Browser monitoring must be enabled.

JavaScript error monitoring must be enabled.

Description

Use this call to notice or log your app's handled or other miscellaneous errors. This is useful when you have caught and handled an error, but you still want to identify it without disrupting your app's operation.

You can also use the API to notice errors that otherwise would be reported without any detail, such as errors that happen during the script initialization or in an inline event handler. The errors will appear in the JavaScript errors page along with other errors New Relic normally detects. For example:

var err = new Error('Report caught error to New Relic');
newrelic.noticeError(err);

Parameters

Parameter Description

$error

error object

Required. Provide a meaningful error message that you can use when analyzing data on New Relic Browser's JavaScript errors page.

Example(s)

Non-critical errors

This example shows how to use the newrelic.noticeError API to report caught errors that you do not want to disrupt your application. This is useful when non-critical errors do not have an impact on the user's experience, but you still want to report them to the developer. The example code safely uses a default foo object in case of bad JSON.

var foo;
try {
  foo = JSON.parse('{ "bar"');
} catch (err) {
  //Report caught error to New Relic
  newrelic.noticeError(err);

  foo = {bar: 'default value'};
}
alert(foo.bar);

Callback with optional error

This example shows how to report an error to New Relic when using the error and response pattern callbacks popularized by Node.js and common in Browserify development. You can replace alert(body); with your own relevant message.

var xhr = require('xhr');
xhr('http://localhost:8080', function (err, resp, body) {
  //Report unthrown error to New Relic
  if (err) return newrelic.noticeError(err);
  //Handle successful response
  alert(body);
});

Promise-based API example

Promises provide a single pattern for handling asynchronous interactions, making it easy to handle asynchronous errors. However, this also makes it easy to ignore errors completely, leaving applications broken in ways that developers cannot see. This example reports those asynchronous errors to New Relic to prevent them from being overlooked.

var rest = require('rest');
rest('/').then(function (res) {
  //Handle successful response
  alert(res.entity);
}, function (err) {
  //Report unthrown error to New Relic
  newrelic.noticeError(err);
});

Browser limitations (Apple Safari and Microsoft Internet Explorer only)

If an error is not thrown, it will not have a stack trace. If you want the newrelic.noticeError API to report a stack trace with all browser types, you must manually throw and then catch the error before you pass it to the API.

try {
  throw errorObject
} catch (err) {
  newrelic.noticeError(err)
}