summaryrefslogtreecommitdiff
path: root/frontend/src/sagas/errors.js
blob: 441f3fb5b94db717c1514ce40b3019cbd34cb40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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/errors')
  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