Skip to content

Commit 2daeb31

Browse files
committedJul 5, 2020
improve exception handling so all exceptions are not caught by thunk middleware.
1 parent e9f7fa5 commit 2daeb31

File tree

1 file changed

+7
-6
lines changed
  • lib/src/commonMain/kotlin/org/reduxkotlin

1 file changed

+7
-6
lines changed
 

‎lib/src/commonMain/kotlin/org/reduxkotlin/Thunk.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ fun <State> createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware<S
2727
{ next: Dispatcher ->
2828
{ action: Any ->
2929
if (action is Function<*>) {
30-
try {
31-
(action as Thunk<*>)(store.dispatch, store.getState, extraArgument)
32-
} catch (e: Exception) {
33-
throw IllegalArgumentException()
34-
// Logger.d("Dispatching functions must use type Thunk: " + e.message)
35-
}
30+
@Suppress("UNCHECKED_CAST")
31+
val thunk = try {
32+
(action as Thunk<*>)
33+
} catch (e: ClassCastException) {
34+
throw IllegalArgumentException("Dispatching functions must use type Thunk:", e)
35+
}
36+
thunk(store.dispatch, store.getState, extraArgument)
3637
} else {
3738
next(action)
3839
}

0 commit comments

Comments
 (0)
Please sign in to comment.