diff --git a/bikeshop_project/assets/js/bikes/actions.js b/bikeshop_project/assets/js/bikes/actions.js index f11a19e..d944ed6 100644 --- a/bikeshop_project/assets/js/bikes/actions.js +++ b/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 setBikesIsFetching = createAction('set bikes.isFetching'); export const setBikesFetched = createAction('set bikes.fetched'); +export const setBikesFetchFailed = createAction('set bikes.fetchFailed'); diff --git a/bikeshop_project/assets/js/bikes/reducers.js b/bikeshop_project/assets/js/bikes/reducers.js index 0b0c956..8b9a351 100644 --- a/bikeshop_project/assets/js/bikes/reducers.js +++ b/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'; export default handleActions({ @@ -14,4 +14,10 @@ export default handleActions({ ...state, fetched: action.payload, }), -}, { entities: {}, isFetching: false, fetched: false }); + [setBikesFetchFailed]: (state, action) => ({ + ...state, + fetchFailed: { + message: action.payload + } + }), +}, { entities: {}, isFetching: false, fetched: false, fetchFailed: undefined }); diff --git a/bikeshop_project/assets/js/bikes/sagas.js b/bikeshop_project/assets/js/bikes/sagas.js index df158ec..0413277 100644 --- a/bikeshop_project/assets/js/bikes/sagas.js +++ b/bikeshop_project/assets/js/bikes/sagas.js @@ -1,5 +1,5 @@ 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 * as schema from './schema'; import Api from './services'; @@ -13,7 +13,7 @@ function* fetchBikes(action) { yield put({ type: setBikes.toString(), payload: normalize(bikes, schema.bikes) }); yield put({ type: setBikesFetched.toString(), payload: true }); } catch (e) { - yield put({ type: 'BIKES_FETCH_FAILED', message: e.message }); + yield put({ type: setBikesFetchFailed.toString(), payload: e.message }); throw e; } finally { yield put({ type: setBikesIsFetching.toString(), payload: false });