The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.
Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Customize the React SDK error handler

This topic describes how to create your own error handler logic for the Optimizely Feature Experimentation React SDK.

In a production environment, you should have full control and visibility over the errors that are happening in your application, including those that would originate from an Optimizely SDK.

Minimum SDK version

v4.0.0+

For versions 3.x and earlier, see React SDK prior to v4.

In v4, error handling uses the createErrorNotifier factory function. The errorHandler parameter on createInstance from v3 is replaced.

Configure error handling

Use createErrorNotifier to create an error notifier and pass it to createInstance:

import {
  createInstance,
  createPollingProjectConfigManager,
  createErrorNotifier,
} from '@optimizely/react-sdk';

const errorNotifier = createErrorNotifier({
  handleError: (error) => {
    console.error('CUSTOM_ERROR_HANDLER');
    console.error(`Error Message: ${error.message}`);
    console.error(`Error Stack: ${error.stack}`);
  },
});

const optimizely = createInstance({
  projectConfigManager: createPollingProjectConfigManager({
    sdkKey: 'YOUR_SDK_KEY',
  }),
  errorNotifier,
});

Default behavior

If no errorNotifier is passed to createInstance, error notification is disabled (no-op handler).