diff --git a/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandler.kt b/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandler.kt index cb9c5e1..88a38a0 100644 --- a/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandler.kt +++ b/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandler.kt @@ -11,6 +11,11 @@ import dev.icerock.moko.mvvm.dispatcher.EventsDispatcher interface ExceptionHandler : ExceptionHandlerBinder { fun handle(block: suspend () -> R): ExceptionHandlerContext + /** + * Directly launches the error-presenter to display the error for exception [throwable]. + */ + fun showError(throwable: Throwable) + companion object { operator fun invoke( exceptionMapper: ExceptionMapper, diff --git a/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/PresenterExceptionHandler.kt b/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/PresenterExceptionHandler.kt index d74006a..8b26d20 100644 --- a/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/PresenterExceptionHandler.kt +++ b/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/PresenterExceptionHandler.kt @@ -20,4 +20,9 @@ internal class PresenterExceptionHandler( override fun handle(block: suspend () -> R): ExceptionHandlerContext { return ExceptionHandlerContext(exceptionMapper, errorEventsDispatcher, onCatch, block) } + + override fun showError(throwable: Throwable) { + val errorValue = exceptionMapper(throwable) + errorEventsDispatcher.dispatchEvent { showError(throwable, errorValue) } + } }