diff --git a/src/public/js/actions/actionCreators.js b/src/public/js/actions/actionCreators.js index d158e10..8e8d5e2 100644 --- a/src/public/js/actions/actionCreators.js +++ b/src/public/js/actions/actionCreators.js @@ -86,7 +86,7 @@ export function fetchMovies() { headers: { 'Authorization': header }, }) .then(response => { - if (response.data && response.data.type && response.data.type === 'error') + if (response.data.type && response.data.type === 'error') { dispatch({ type: ADD_ERROR, @@ -99,8 +99,20 @@ export function fetchMovies() { type: MOVIE_LIST_FETCH_FULFILLED, payload: response, }) - }).catch(error => { - console.log(error) + }) + .catch(error => { + // Unauthorized + if (error.response.status == 401) { + dispatch({ + type: USER_LOGOUT, + }) + } + dispatch({ + type: ADD_ERROR, + payload: { + message: error.response.data, + } + }) }) } } diff --git a/src/public/js/app.js b/src/public/js/app.js index 2082f3b..cde690d 100644 --- a/src/public/js/app.js +++ b/src/public/js/app.js @@ -1,3 +1,4 @@ +import 'babel-polyfill' import React from 'react' import ReactDOM from 'react-dom' import { bindActionCreators } from 'redux' diff --git a/yarn.lock b/yarn.lock index d116c89..ef31858 100644 --- a/yarn.lock +++ b/yarn.lock @@ -595,7 +595,7 @@ babel-plugin-transform-strict-mode@^6.18.0: babel-runtime "^6.0.0" babel-types "^6.18.0" -babel-polyfill@^6.16.0: +babel-polyfill: version "6.16.0" resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.16.0.tgz#2d45021df87e26a374b6d4d1a9c65964d17f2422" dependencies: