From 5be812504d15c6ac5568e74f3452fc7494d111c7 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Wed, 5 Jul 2017 09:04:19 +1200 Subject: [PATCH] Refresh token when detecting expired token --- src/js/services/spotify/actions.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/js/services/spotify/actions.js b/src/js/services/spotify/actions.js index 2064e8e6..01efb703 100755 --- a/src/js/services/spotify/actions.js +++ b/src/js/services/spotify/actions.js @@ -53,16 +53,20 @@ const sendRequest = ( dispatch, getState, endpoint, method = 'GET', data = false }, (xhr, status, error) => { 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 var message = xhr.responseText + var status = null var response = JSON.parse(xhr.responseText) if (response.error && 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'))