From 333c12312ce19595e21da5edd87f99f32c5c57e1 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Fri, 27 Mar 2020 01:42:52 +0100 Subject: Add error handling saga printing errors in console --- .../org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'sw-ui-kt/src/main/kotlin') 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() val player = session.chooseName(action.playerName) dispatch(SetCurrentPlayerAction(player)) - return session } -- cgit