Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket

Customize error handler

This topic describes how to create your own error handler logic.

You can provide your own custom error handler logic to standardize across your production environment.

This error handler is called when an unknown feature key is referenced.

See the code example below. If the error handler is not overridden, a no-op error handler is used by default.

from optimizely.error_handler import NoOpErrorHandler as error_handler
from optimizely import optimizely

optimizely_client = optimizely.Optimizely(datafile,

To have finer grained control over your SDK configuration in a production environment, you can also pass in a custom error handler for your Optimizely client. A custom error handler can allow you to have more control over how you want to handle any errors coming from the Optimizely SDK.

from optimizely import optimizely
from optimizely import error_handler

class MyCustomErrorHandler(error_handler.BaseHandler):
  """ Custom error handler class that extends and overrides the 
      handle_error method allowing you to define custom behavior. 
  def handle_error(error):
    # You can put custom logic here about how you want to handle the error.
    # For example here we simply raise the error.
    raise error

# Here we initialize the SDK with the custom error handler.
optimizely_client = optimizely.Optimizely(datafile, error_handler=MyCustomErrorHandler)