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 in the following situations:
- Unknown experiment key referenced
- Unknown event key referenced
See the code examples below. If the error handler is not overridden, a no-op error handler is used by default.
/**
* Provide your own custom error handler logic by replacing the
* `errorHandler` property in the `OPTLYManagerBuilder` object
* during initialization. The error handler you create must
* conform to the `OPTLYErrorHandler` protocol. Overriding this
* module will allow you to standardize error and exception
* handling across your application.
*/
CustomErrorHandler *customErrorHandler = [[CustomErrorHandler alloc] init];
OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
builder.sdkKey = @"SDK_KEY_HERE";
builder.errorHandler = customErrorHandler;
}]];
/**
* Provide your own custom error handler logic by replacing
* the `errorHandler` property in the `OPTLYManagerBuilder`
* object during initialization. The error handler you create
* must conform to the `OPTLYErrorHandler` protocol.
* Overriding this module will allow you to standardize error
* and exception handling across your application.
*/
let customErrorHandler: CustomErrorHandler? = CustomErrorHandler()
let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
builder!.sdkKey = "SDK_KEY_HERE"
builder!.errorHandler = customErrorHandler
}))
Updated over 2 years ago