aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/store
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/store')
-rw-r--r--src/client/react/store/actions.js12
-rw-r--r--src/client/react/store/reducers.js17
2 files changed, 20 insertions, 9 deletions
diff --git a/src/client/react/store/actions.js b/src/client/react/store/actions.js
index 2157030..131bcaa 100644
--- a/src/client/react/store/actions.js
+++ b/src/client/react/store/actions.js
@@ -5,6 +5,7 @@ import { selectUser, selectWeek, selectCurrentWeek } from './selectors';
import purifyWeek from '../lib/purifyWeek';
import withinRange from '../lib/withinRange';
import extractSchedule from '../lib/extractSchedule';
+import rejectIfBadStatus from '../lib/rejectIfBadStatus';
function updatePathname(pathname = '') {
return (dispatch, getState) => {
@@ -93,8 +94,8 @@ const fetchScheduleSuccess = (user, week, htmlStr) => ({
type: 'VIEW/FETCH_SCHEDULE_SUCCESS', user, week, htmlStr,
});
-const fetchScheduleError = (user, week) => ({
- type: 'VIEW/FETCH_SCHEDULE_ERROR', user, week,
+const fetchScheduleError = (user, week, statusCode) => ({
+ type: 'VIEW/FETCH_SCHEDULE_ERROR', user, week, statusCode,
});
@@ -110,17 +111,18 @@ export function fetchScheduleIfNeeded(user, week) {
dispatch(fetchScheduleStart(user, week));
fetch(`/get/${user}?week=${week}`)
+ .then(rejectIfBadStatus)
.then(r => r.text())
.then(
- // success
+ // success
(htmlStr) => {
dispatch(fetchScheduleSuccess(user, week, htmlStr));
},
// error
- () => {
+ (statusCode) => {
// TODO: Handle error status
- dispatch(fetchScheduleError(user, week));
+ dispatch(fetchScheduleError(user, week, statusCode));
},
);
};
diff --git a/src/client/react/store/reducers.js b/src/client/react/store/reducers.js
index 3e39096..b1af46f 100644
--- a/src/client/react/store/reducers.js
+++ b/src/client/react/store/reducers.js
@@ -30,17 +30,25 @@ const DEFAULT_STATE = {
const schedule = (state = {}, action) => {
switch (action.type) {
- case 'VIEW/FETCH_SCHEDULE_START':
+ case 'VIEW/FETCH_SCHEDULE_START': {
return {
- ...state,
state: 'FETCHING',
};
- case 'VIEW/FETCH_SCHEDULE_SUCCESS':
+ }
+ case 'VIEW/FETCH_SCHEDULE_SUCCESS': {
return {
- ...state,
state: 'FINISHED',
htmlStr: action.htmlStr,
};
+ }
+ case 'VIEW/FETCH_SCHEDULE_ERROR': {
+ const { statusCode } = action;
+
+ return {
+ state: 'ERROR',
+ statusCode,
+ };
+ }
default:
return state;
}
@@ -105,6 +113,7 @@ function reducer(state = DEFAULT_STATE, action) {
case 'VIEW/FETCH_SCHEDULE_START':
case 'VIEW/FETCH_SCHEDULE_SUCCESS':
+ case 'VIEW/FETCH_SCHEDULE_ERROR':
return {
...state,
schedules: {