summaryrefslogtreecommitdiff
path: root/frontend/src/sagas/errors.js
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-05-13 22:18:56 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-05-13 22:18:56 +0200
commite7606b72118f71097a0a7f75fb735750f905c24a (patch)
tree6cf01487cf2c669e6231c2c16ea3d50093319b0b /frontend/src/sagas/errors.js
parentFix getPlayers that in fact takes an immutable List instead of JS array (diff)
downloadseven-wonders-e7606b72118f71097a0a7f75fb735750f905c24a.tar.gz
seven-wonders-e7606b72118f71097a0a7f75fb735750f905c24a.tar.bz2
seven-wonders-e7606b72118f71097a0a7f75fb735750f905c24a.zip
Migrate to seamless immutable
Resolves: https://github.com/luxons/seven-wonders/issues/6
Diffstat (limited to 'frontend/src/sagas/errors.js')
-rw-r--r--frontend/src/sagas/errors.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/frontend/src/sagas/errors.js b/frontend/src/sagas/errors.js
new file mode 100644
index 00000000..6d4df93d
--- /dev/null
+++ b/frontend/src/sagas/errors.js
@@ -0,0 +1,23 @@
+import { apply, call, cancelled, put, take } from 'redux-saga/effects'
+
+import { createSubscriptionChannel } from '../utils/websocket'
+import { actions } from '../redux/errors'
+
+export default function *errorHandlingSaga({ socket }) {
+ const errorChannel = yield call(createSubscriptionChannel, socket, '/user/queue/error')
+ try {
+ while (true) {
+ const error = yield take(errorChannel)
+ yield* handleOneError(error)
+ }
+ } finally {
+ if (yield cancelled()) {
+ yield apply(errorChannel, errorChannel.close)
+ }
+ }
+}
+
+function *handleOneError(error) {
+ console.error("Error received on web socket channel", error)
+ yield put(actions.errorReceived(error))
+}
bgstack15