summaryrefslogtreecommitdiff
path: root/frontend/src/containers/App/saga.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/containers/App/saga.js')
-rw-r--r--frontend/src/containers/App/saga.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/frontend/src/containers/App/saga.js b/frontend/src/containers/App/saga.js
new file mode 100644
index 00000000..0c212142
--- /dev/null
+++ b/frontend/src/containers/App/saga.js
@@ -0,0 +1,28 @@
+import { put, take } from 'redux-saga/effects'
+import { eventChannel } from 'redux-saga'
+
+function createSocketChannel(socket) {
+ return eventChannel(emit => {
+ const errorHandler = event => emit(JSON.parse(event.body))
+
+ const userErrors = socket.subscribe('/user/queue/errors', errorHandler)
+
+ const unsubscribe = () => {
+ userErrors.unsubscribe()
+ }
+
+ return unsubscribe
+ })
+}
+
+export function* watchOnErrors(socketConnection) {
+ const { socket } = socketConnection
+ const socketChannel = createSocketChannel(socket)
+
+ while (true) {
+ const payload = yield take(socketChannel)
+ yield put({ type: 'USER_ERROR', payload })
+ }
+}
+
+export default watchOnErrors
bgstack15