---
title: Customize error handler for the JavaScript SDK v6+
slug: feature-experimentation/docs/customize-error-handler-for-the-javascript-sdk
docTags: 
createdAt: 2026-08-05T20:39:54.000Z
---

## Minimum SDK version

v6.0.0+

For versions 5.3.5 and below, see [JavaScript (Browser) SDK](docId\:KymcQ9kjPZNY_sBCmhX2X) or [JavaScript (Node) SDK](docId\:kj4xDRaFGIbKrvpDTLRjx). See the [SDK compatibility matrix](docId:2shbZfPCkPAZ0mlZpL1TU) documentation for a list of current SDK releases and the features they support.

## Description

In production, it is important to monitor and manage errors from all parts of your application, including those from the Optimizely Feature Experimentation JavaScript SDK.

The SDK provides an `errorNotifier` configuration option that lets you track and respond to these errors. To use it, create an error notifier using the `createErrorNotifier` factory function and pass it to `createInstance`.

The `createErrorNotifier` function requires an `ErrorHandler`, which defines how to handle each error. You can use this handler to log errors to the console, forward them to an external monitoring service, or take any other appropriate action.

The following code sample is an example of using the notifier with a custom error handler:

```javascript
import {
  createInstance,
  createPollingProjectConfigManager,
  createErrorNotifier,
} from "@optimizely/optimizely-sdk";
 
const pollingConfigManager = createPollingProjectConfigManager({
  sdkKey: SDK_KEY,
});

const customErrorHandler = {
  handleError: (error) => {
    console.log('CUSTOM_ERROR_HANDLER');
    console.log('****');
    console.log(`Error Message: ${error.message}`);
    console.log(`Error Stack: ${error.stack}`);
    console.log('****');
  }
}

const errorNotifier = createErrorNotifier(customErrorHandler)

const optimizely = createInstance({
  projectConfigManager: pollingConfigManager,
  errorNotifier
});
```
