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.
use Optimizely\ErrorHandler\DefaultErrorHandler;
$optimizelyClient = new Optimizely($datafile, null, null, new DefaultErrorHandler());
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.
use Optimizely\ErrorHandler\ErrorHandlerInterface;
/**
* Class MyCustomErrorHandler
*
* Custom error handler class that extends and overrides the
* handleError method allowing you to define custom behavior.
*
*/
class MyCustomErrorHandler implements ErrorHandlerInterface
{
public function handleError(Exception $error)
{
// You can put custom logic here about how you want to handle the error.
// For example here we simply throw the error.
throw $error;
}
}
// This error handler can then be used when initializing the Optimizely SDK.
$optimizelyClient = new Optimizely($datafile, null, null, new MyCustomErrorHandler());
Updated almost 3 years ago