blob: 6d4df93d3b4a3e3b64b3143790558bea2bcea5f7 (
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/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))
}
|