Skip to content

Files

Latest commit

Jun 26, 2024
ae51cf7 · Jun 26, 2024

History

History
114 lines (90 loc) · 3.79 KB

File metadata and controls

114 lines (90 loc) · 3.79 KB
title type shortDescription tags metaDescription redirects freshnessValidatedDate
setErrorHandler
apiDoc
Allows selective ignoring and grouping of known errors that the browser agent captures.
Browser
Browser monitoring
Browser agent and SPA API
Browser monitoring API call to allow selective ignoring and grouping of known errors captured by the agent.
/docs/browser/new-relic-browser/browser-agent-apis/browser-api-newrelicseterrorhandler
/docs/browser/new-relic-browser/browser-agent-api/browser-api-newrelicseterrorhandler
/docs/browser/new-relic-browser/browser-agent-spa-api/newrelicseterrorhandler-browser-agent-api
docs/browser/new-relic-browser/browser-agent-spa-api/set-error-handler
never

Syntax

newrelic.setErrorHandler(function $callback)

Allows selective ignoring and grouping of known errors that the browser agent captures.

Requirements

  • Browser Pro or Pro+SPA agent (v974 or higher)

    • For error grouping capability, v1.230.0 or higher is required.
  • If you're using npm to install the browser agent, you must enable the jserrors feature when instantiating the BrowserAgent class. In the features array, add the following:

    import { JSErrors } from '@newrelic/browser-agent/features/jserrors';
    
    const options = {
      info: { ... },
      loader_config: { ... },
      init: { ... },
      features: [
        JSErrors
      ]
    }

    For more information, see the npm browser installation documentation.

Description

The newrelic.setErrorHandler() API call allows you to selectively ignore known errors that the browser agent captures. It takes a single error handler function, which will be called for each error that the browser agent captures. If the handler returns true, New Relic does not record the error. Otherwise the error will be processed normally.

In addition, later versions of the agent support fingerprinting or grouping of exceptions with a custom provided label. To do this, return an object instead of a boolean with a group property set to the desired string. It's important to know that providing an empty string, or any object that does not conform to this exact spec, is treated the same as the true case, for which the error will be ignored. This behavior is backwards compatible with prior versions.

Parameters

  <th>
    Description
  </th>
</tr>
Parameter
`$callback`
    _function_
  </td>

  <td>
    Required<DNT>**.**</DNT> When an error occurs, the callback is called with the error object as a parameter. The callback will be called with each error, so it is not specific to one error.
  </td>
</tr>

Examples

Use a basic error handler function [#include-error]

Include the error object inside of the callback function to ignore specific errors that the browser agent captures.

newrelic.setErrorHandler(function(err) {
  if (shouldIgnoreError(err)) {
    return true;
  } else {
    return false;
  }
});

Fingerprinting errors in handler function

Assign custom labels to specific errors for view in the Errors Inbox UI.

newrelic.setErrorHandler(function(err) {
  if (isReferenceError(err)) {
    return { group: 'My reference errors' }; // error is included and tagged under this label
  } else if (isSomeSpecificError(err)) {
    return { group: '' }; // error will be excluded!
    // return { Group: 'still excluded - prop name has capital G!' };
  } else {
    return false; // error is included without any label
  }
})