diff options
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r-- | frontend/src/sagas/errors.js | 20 | ||||
-rw-r--r-- | frontend/src/sagas/gameBrowser.js | 16 | ||||
-rw-r--r-- | frontend/src/sagas/home.js | 17 |
3 files changed, 36 insertions, 17 deletions
diff --git a/frontend/src/sagas/errors.js b/frontend/src/sagas/errors.js index 441f3fb5..9808fe41 100644 --- a/frontend/src/sagas/errors.js +++ b/frontend/src/sagas/errors.js @@ -1,8 +1,11 @@ +import React from 'react' import { apply, call, cancelled, put, take } from 'redux-saga/effects' import { createSubscriptionChannel } from '../utils/websocket' import { actions } from '../redux/errors' +import {toastr} from 'react-redux-toastr' + export default function *errorHandlingSaga({ socket }) { const errorChannel = yield call(createSubscriptionChannel, socket, '/user/queue/errors') try { @@ -12,12 +15,23 @@ export default function *errorHandlingSaga({ socket }) { } } finally { if (yield cancelled()) { + console.log('Error management saga cancelled') yield apply(errorChannel, errorChannel.close) } } } -function *handleOneError(error) { - console.error("Error received on web socket channel", error) - yield put(actions.errorReceived(error)) +function *handleOneError(err) { + console.error("Error received on web socket channel", err) + const msg = buildMsg(err) + yield apply(toastr, toastr.error, [msg, {icon: 'error'}]) + yield put(actions.errorReceived(err)) +} + +function buildMsg(err) { + if (err.details.length > 0) { + return err.details.map(d => d.message).join('\n') + } else { + return err.message + } } diff --git a/frontend/src/sagas/gameBrowser.js b/frontend/src/sagas/gameBrowser.js index 10d6ec1d..b12587ef 100644 --- a/frontend/src/sagas/gameBrowser.js +++ b/frontend/src/sagas/gameBrowser.js @@ -3,7 +3,7 @@ import { createSubscriptionChannel } from '../utils/websocket' import { push } from 'react-router-redux' import { normalize } from 'normalizr' -import { game as gameSchema, gameList as gameListSchema} from '../schemas/games' +import { game as gameSchema, gameList as gameListSchema } from '../schemas/games' import { actions as gameActions, types } from '../redux/games' import { actions as playerActions } from '../redux/players' @@ -39,15 +39,17 @@ function *watchLobbyJoined({socket}) { } function *createGame({socket}) { - const {gameName} = yield take(types.REQUEST_CREATE_GAME) - - yield apply(socket, socket.send, ['/app/lobby/create', JSON.stringify({gameName}), {}]) + while (true) { + const {gameName} = yield take(types.REQUEST_CREATE_GAME) + yield apply(socket, socket.send, ['/app/lobby/create', JSON.stringify({gameName}), {}]) + } } function *joinGame({socket}) { - const {gameId} = yield take(types.REQUEST_JOIN_GAME) - - yield apply(socket, socket.send, ['/app/lobby/join', JSON.stringify({gameId}), {}]) + while (true) { + const {gameId} = yield take(types.REQUEST_JOIN_GAME) + yield apply(socket, socket.send, ['/app/lobby/join', JSON.stringify({gameId}), {}]) + } } function *gameBrowserSaga(socketConnection) { diff --git a/frontend/src/sagas/home.js b/frontend/src/sagas/home.js index 99e6f954..151fcb57 100644 --- a/frontend/src/sagas/home.js +++ b/frontend/src/sagas/home.js @@ -5,17 +5,20 @@ import { push } from 'react-router-redux' import { actions, types } from '../redux/players' function *sendUsername({ socket }) { - const {username} = yield take(types.REQUEST_CHOOSE_USERNAME) - - yield apply(socket, socket.send, ['/app/chooseName', JSON.stringify({ playerName: username })]) + while (true) { + const {username} = yield take(types.REQUEST_CHOOSE_USERNAME) + yield apply(socket, socket.send, ['/app/chooseName', JSON.stringify({playerName: username})]) + } } function *validateUsername({ socket }) { const usernameChannel = yield call(createSubscriptionChannel, socket, '/user/queue/nameChoice') - const user = yield take(usernameChannel) - yield put(actions.setCurrentPlayer(user)) - yield apply(usernameChannel, usernameChannel.close) - yield put(push('/games')) + while (true) { + const user = yield take(usernameChannel) + yield put(actions.setCurrentPlayer(user)) + yield apply(usernameChannel, usernameChannel.close) + yield put(push('/games')) + } } function *usernameChoiceSaga(wsConnection) { |