diff options
Diffstat (limited to 'frontend/src/sagas/errors.js')
-rw-r--r-- | frontend/src/sagas/errors.js | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/frontend/src/sagas/errors.js b/frontend/src/sagas/errors.js index e43875ae..86fa0124 100644 --- a/frontend/src/sagas/errors.js +++ b/frontend/src/sagas/errors.js @@ -1,12 +1,13 @@ -import { apply, call, cancelled, take } from 'redux-saga/effects'; -import { createSubscriptionChannel } from '../utils/websocket'; -import { toastr } from 'react-redux-toastr'; +import {apply, cancelled, take} from 'redux-saga/effects'; +import {toastr} from 'react-redux-toastr'; +import {ApiError, SevenWondersSession} from '../api/sevenWondersApi'; +import type {Channel} from 'redux-saga'; -export default function* errorHandlingSaga({ socket }) { - const errorChannel = yield call(createSubscriptionChannel, socket, '/user/queue/errors'); +export default function* errorHandlingSaga(session: SevenWondersSession) { + const errorChannel: Channel<ApiError> = yield apply(session, session.watchErrors, []); try { while (true) { - const error = yield take(errorChannel); + const error: ApiError = yield take(errorChannel); yield* handleOneError(error); } } finally { @@ -17,13 +18,13 @@ export default function* errorHandlingSaga({ socket }) { } } -function* handleOneError(err) { +function* handleOneError(err: ApiError) { console.error('Error received on web socket channel', err); const msg = buildMsg(err); yield apply(toastr, toastr.error, [msg, { icon: 'error' }]); } -function buildMsg(err) { +function buildMsg(err: ApiError): string { if (err.details.length > 0) { return err.details.map(d => d.message).join('\n'); } else { |