From 7cb835aac44e34058f3909e5f5f06eb1f0b5c503 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 5 Jan 2016 12:34:50 -0800 Subject: [PATCH] Add error handling In the near future these will be handled by a toast. --- client/index.js | 6 ++++++ common/app/routes/Hikes/flux/Actions.js | 17 ++++++----------- common/app/routes/Jobs/flux/Actions.js | 12 +++++++----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/client/index.js b/client/index.js index e85045329f..c3796092cb 100644 --- a/client/index.js +++ b/client/index.js @@ -53,6 +53,12 @@ app$({ history, location: appLocation }) .doOnNext(title => document.title = title) .subscribe(() => {}); + appStore$ + .pluck('err') + .filter(err => !!err) + .distinctUntilChanged() + .subscribe(err => console.error(err)); + synchroniseHistory( history, updateLocation, diff --git a/common/app/routes/Hikes/flux/Actions.js b/common/app/routes/Hikes/flux/Actions.js index 4556308871..fb0dd81e8b 100644 --- a/common/app/routes/Hikes/flux/Actions.js +++ b/common/app/routes/Hikes/flux/Actions.js @@ -80,9 +80,9 @@ export default Actions({ } }; }) - .catch(err => { - console.error(err); - }); + .catch(err => Observable.just({ + transform(state) { return { ...state, err }; } + })); }, toggleQuestions() { @@ -243,13 +243,8 @@ export default Actions({ }) .delay(300) .startWith(correctAnswer) - .catch(err => { - console.error(err); - return Observable.just({ - set: { - error: err - } - }); - }); + .catch(err => Observable.just({ + transform(state) { return { ...state, err }; } + })); } }); diff --git a/common/app/routes/Jobs/flux/Actions.js b/common/app/routes/Jobs/flux/Actions.js index ee50dd419f..a3717a3653 100644 --- a/common/app/routes/Jobs/flux/Actions.js +++ b/common/app/routes/Jobs/flux/Actions.js @@ -1,5 +1,7 @@ import { Actions } from 'thundercats'; import store from 'store'; +import { Observable } from 'rx'; + import { nameSpacedTransformer } from '../../../../utils'; const assign = Object.assign; @@ -50,7 +52,7 @@ export default Actions({ }; } })) - .catch(err => ({ + .catch(err => Observable.just({ transform(state) { return { ...state, err }; } @@ -63,7 +65,7 @@ export default Actions({ return { ...state, currentJob: job }; }) })) - .catch(err => ({ + .catch(err => Observable.just({ transform(state) { return { ...state, err }; } @@ -76,9 +78,9 @@ export default Actions({ return { ...state, jobs }; }) })) - .catch(err => ({ + .catch(err => Observable.just({ transform(state) { - return { state, err }; + return { ...state, err }; } })); }, @@ -161,7 +163,7 @@ export default Actions({ })) }; }) - .catch(err => ({ + .catch(err => Observable.just({ transform(state) { return { ...state, err }; }