Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

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 GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

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.

# In a development environment, you might want the SDK to raise errors. In that case you can use out built-in RaiseErrorHandler
error_handler = Optimizely::RaiseErrorHandler.new

# You can also define your own error handler
class CustomErrorHandler < Optimizely::BaseErrorHandler

  def handle_error(error)
    # You can handle this error in any way you'd like
    puts error
  end

end

error_handler = CustomErrorHandler.new

# Pass the error handler into the Optimizely instance
optimizely_client = Optimizely::Project.new(datafile,
                                            Optimizely::EventDispatcher.new,
                                            Optimizely::NoOpLogger.new,
                                            error_handler
                                            )