Skip to content

Commit 1dc8db3

Browse files
authored
Merge pull request #15 from reduxkotlin/feature/improve-exception
Stop catching all exceptions in thunk middleware.
2 parents e9f7fa5 + 2daeb31 commit 1dc8db3

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)