Logout user on http status unauthorized

This commit is contained in:
Grégoire Delattre 2016-11-16 21:11:49 +01:00
parent 7dc53ca531
commit 4108e3a2ca
3 changed files with 17 additions and 4 deletions

View File

@ -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,
}
})
})
}
}

View File

@ -1,3 +1,4 @@
import 'babel-polyfill'
import React from 'react'
import ReactDOM from 'react-dom'
import { bindActionCreators } from 'redux'

View File

@ -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: