diff options
author | jbion <joffrey.bion@amadeus.com> | 2017-05-19 20:17:35 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-20 00:12:39 +0200 |
commit | a13f913c6a594a14a2cb9ab42dbd0493372583fb (patch) | |
tree | 2ac200b06532b7be09b0192a4455ab132cd5010b /frontend/src/sagas/errors.js | |
parent | Set versions of packages to latest (diff) | |
download | seven-wonders-a13f913c6a594a14a2cb9ab42dbd0493372583fb.tar.gz seven-wonders-a13f913c6a594a14a2cb9ab42dbd0493372583fb.tar.bz2 seven-wonders-a13f913c6a594a14a2cb9ab42dbd0493372583fb.zip |
Add error toasts
Diffstat (limited to 'frontend/src/sagas/errors.js')
-rw-r--r-- | frontend/src/sagas/errors.js | 20 |
1 files changed, 17 insertions, 3 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 + } } |