• English日本語한국어
  • Log inStart now

noticeError

Syntax

newrelic.noticeError(error object $error, [object $customAttributes])

Identifies a browser error without disrupting your app's operations.

Requirements

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 Errors page along with other errors New Relic normally detects. They will also be recorded as a JavaScriptError event. For example:

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

Note: If more than 1000 JavaScriptError events is sent in a single request, only 1000 separate events is recorded. However, total number of events is preseved internally and accessible by using EXTRAPOLATE query clause.

Parameters

Parameter

Description

$error

error object

Required. Provide a meaningful error message that you can use when analyzing data on browser's Errors page.

$customAttributes object

Optional. An object containing name/value pairs representing custom attributes.

Examples

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);
});

Capturing custom attributes example

try {
// code that throws an error
} catch (err) {
newrelic.noticeError(err, { attribute1: 'value1', attribute2: 2 });
}

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);
}
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.