File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
errors/src/commonMain/kotlin/dev/icerock/moko/errors/mappers
sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ object ExceptionMappersStorage {
2020 fallback = { MR .strings.moko_errors_unknownError.desc() }
2121 )
2222 )
23- private val notifiers: MutableList < (Throwable , KClass <* >) -> Unit > = mutableListOf ()
23+ private val notifiers: MutableList < (Throwable , KClass <* >, Any ) -> Unit > = mutableListOf ()
2424
2525 private fun <T : Any > getOrCreateContainer (resultClass : KClass <T >): MappersContainer <T > {
2626 val existContainer: MappersContainer <* >? = containers[resultClass]
@@ -132,10 +132,11 @@ object ExceptionMappersStorage {
132132 ? : container.fallback
133133
134134 return { exception ->
135+ val result: T = mapper(exception)
135136 notifiers.forEach { notifier ->
136- notifier(exception, resultClass)
137+ notifier(exception, resultClass, result )
137138 }
138- mapper(exception)
139+ result
139140 }
140141 }
141142
@@ -208,7 +209,7 @@ object ExceptionMappersStorage {
208209 * @param block - lambda that will be called when exception map to some class
209210 */
210211 fun onEach (
211- block : (Throwable , KClass <* >) -> Unit
212+ block : (Throwable , KClass <* >, Any ) -> Unit
212213 ): ExceptionMappersStorage {
213214 notifiers.add(block)
214215 return this
Original file line number Diff line number Diff line change @@ -14,4 +14,7 @@ fun initExceptionStorage() {
1414 .register<IllegalArgumentException , StringDesc > {
1515 MR .strings.illegalArgumentText.desc()
1616 }
17+ .onEach { throwable, kClass, result ->
18+ println (" $throwable mapped to $kClass with result $result " )
19+ }
1720}
You can’t perform that action at this time.
0 commit comments