ErrorHandler
Decides what a screen does when one of its event handlers fails.
Event handlers do not catch their own failures: they throw, and the EventRouter passes each failure here. A screen therefore has one place that turns an exception into something its UI can show, and one place to log it.
class TaskListErrorHandler(
private val logger: Logger,
) : ErrorHandler<TaskListEvent, TaskListUiState, TaskListEffect> {
override fun handle(
event: TaskListEvent,
error: Throwable,
store: ScreenStore<TaskListUiState, TaskListEffect>,
) {
logger.warn("$event failed", error)
store.emit(TaskListEffect.ShowFailure(error.toFailureReason()))
}
}Content copied to clipboard
Like an event handler, it holds nothing about the screen: the state and the effects come in with each call. Give it to the screen's router through the errorHandler parameter of the EventRouter function.