Logout user on http status unauthorized
This commit is contained in:
parent
7dc53ca531
commit
4108e3a2ca
@ -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,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'babel-polyfill'
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import { bindActionCreators } from 'redux'
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user