Refresh token when detecting expired token

This commit is contained in:
James Barnsley
2017-07-05 09:04:19 +12:00
parent a5b1167251
commit 5be812504d

View File

@ -54,15 +54,19 @@ const sendRequest = ( dispatch, getState, endpoint, method = 'GET', data = false
(xhr, status, error) => { (xhr, status, error) => {
dispatch(uiActions.stopLoading(loader_key)) dispatch(uiActions.stopLoading(loader_key))
// TODO: Catch 403 token_expired and force renewal
// Android Chrome mini-app doesn't seem to check date properly
// alert(error)
// Get the error message, jsson decode if necessary // Get the error message, jsson decode if necessary
var message = xhr.responseText var message = xhr.responseText
var status = null
var response = JSON.parse(xhr.responseText) var response = JSON.parse(xhr.responseText)
if (response.error && response.error.message){ if (response.error && response.error.message){
message = response.error.message message = response.error.message
status = response.error.status
}
// TODO: Instead of allowing request to fail before renewing the token, once refreshed
// we should retry the original request(s)
if (message == 'The access token expired'){
dispatch(refreshToken(dispatch, getState))
} }
dispatch(uiActions.createNotification('Spotify: '+message,'bad')) dispatch(uiActions.createNotification('Spotify: '+message,'bad'))