Browse Source

Handle errors.

feature/bike-tracking
Drew Larson 8 years ago
parent
commit
5151d089a1
  1. 1
      bikeshop_project/assets/js/bikes/actions.js
  2. 10
      bikeshop_project/assets/js/bikes/reducers.js
  3. 4
      bikeshop_project/assets/js/bikes/sagas.js

1
bikeshop_project/assets/js/bikes/actions.js

@ -4,3 +4,4 @@ export const fetchBikes = createAction('fetch bikes');
export const setBikes = createAction('set bikes'); export const setBikes = createAction('set bikes');
export const setBikesIsFetching = createAction('set bikes.isFetching'); export const setBikesIsFetching = createAction('set bikes.isFetching');
export const setBikesFetched = createAction('set bikes.fetched'); export const setBikesFetched = createAction('set bikes.fetched');
export const setBikesFetchFailed = createAction('set bikes.fetchFailed');

10
bikeshop_project/assets/js/bikes/reducers.js

@ -1,4 +1,4 @@
import { setBikes, setBikesFetched, setBikesIsFetching } from './actions'; import { setBikes, setBikesFetched, setBikesIsFetching, setBikesFetchFailed } from './actions';
import { handleActions } from 'redux-actions'; import { handleActions } from 'redux-actions';
export default handleActions({ export default handleActions({
@ -14,4 +14,10 @@ export default handleActions({
...state, ...state,
fetched: action.payload, fetched: action.payload,
}), }),
}, { entities: {}, isFetching: false, fetched: false }); [setBikesFetchFailed]: (state, action) => ({
...state,
fetchFailed: {
message: action.payload
}
}),
}, { entities: {}, isFetching: false, fetched: false, fetchFailed: undefined });

4
bikeshop_project/assets/js/bikes/sagas.js

@ -1,5 +1,5 @@
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'; import { call, put, takeEvery, takeLatest } from 'redux-saga/effects';
import { fetchBikes as fetchBikesAction, setBikes, setBikesIsFetching, setBikesFetched } from './actions'; import { fetchBikes as fetchBikesAction, setBikes, setBikesIsFetching, setBikesFetched, setBikesFetchFailed } from './actions';
import { normalize } from 'normalizr'; import { normalize } from 'normalizr';
import * as schema from './schema'; import * as schema from './schema';
import Api from './services'; import Api from './services';
@ -13,7 +13,7 @@ function* fetchBikes(action) {
yield put({ type: setBikes.toString(), payload: normalize(bikes, schema.bikes) }); yield put({ type: setBikes.toString(), payload: normalize(bikes, schema.bikes) });
yield put({ type: setBikesFetched.toString(), payload: true }); yield put({ type: setBikesFetched.toString(), payload: true });
} catch (e) { } catch (e) {
yield put({ type: 'BIKES_FETCH_FAILED', message: e.message }); yield put({ type: setBikesFetchFailed.toString(), payload: e.message });
throw e; throw e;
} finally { } finally {
yield put({ type: setBikesIsFetching.toString(), payload: false }); yield put({ type: setBikesIsFetching.toString(), payload: false });

Loading…
Cancel
Save