summaryrefslogtreecommitdiff
path: root/sw-ui-kt/src/main/kotlin
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-03-27 01:42:52 +0100
committerJoffrey Bion <joffrey.bion@booking.com>2020-03-27 10:59:39 +0100
commit333c12312ce19595e21da5edd87f99f32c5c57e1 (patch)
tree38b37f85ce14292333362296716fc6564179e8b8 /sw-ui-kt/src/main/kotlin
parentAdd missing prepareMove method in SwClient (diff)
downloadseven-wonders-333c12312ce19595e21da5edd87f99f32c5c57e1.tar.gz
seven-wonders-333c12312ce19595e21da5edd87f99f32c5c57e1.tar.bz2
seven-wonders-333c12312ce19595e21da5edd87f99f32c5c57e1.zip
Add error handling saga printing errors in console
Diffstat (limited to 'sw-ui-kt/src/main/kotlin')
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt17
1 files changed, 15 insertions, 2 deletions
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt
index a0cd6f3c..2a501566 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt
@@ -1,6 +1,7 @@
package org.luxons.sevenwonders.ui.redux.sagas
import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.launch
import org.luxons.sevenwonders.client.SevenWondersClient
import org.luxons.sevenwonders.client.SevenWondersSession
import org.luxons.sevenwonders.ui.redux.RequestChooseName
@@ -18,6 +19,10 @@ suspend fun SwSagaContext.rootSaga() = coroutineScope {
val session = SevenWondersClient().connect("localhost:8000")
console.info("Connected to Seven Wonders web socket API")
+ launch {
+ errorSaga(session)
+ }
+
val player = session.chooseName(action.playerName)
dispatch(SetCurrentPlayerAction(player))
@@ -31,9 +36,17 @@ suspend fun SwSagaContext.rootSaga() = coroutineScope {
}
}
-private suspend fun SwSagaContext.homeSaga(session: SevenWondersSession): SevenWondersSession {
+private suspend fun errorSaga(session: SevenWondersSession) {
+ val errorsSub = session.watchErrors()
+ for (err in errorsSub.messages) {
+ // TODO use blueprintjs toaster
+ console.error("${err.code}: ${err.message}")
+ console.error(JSON.stringify(err))
+ }
+}
+
+private suspend fun SwSagaContext.homeSaga(session: SevenWondersSession) {
val action = next<RequestChooseName>()
val player = session.chooseName(action.playerName)
dispatch(SetCurrentPlayerAction(player))
- return session
}
bgstack15