diff --git a/src/js/services/core/middleware.js b/src/js/services/core/middleware.js index ab650167..5bcb5d26 100755 --- a/src/js/services/core/middleware.js +++ b/src/js/services/core/middleware.js @@ -30,6 +30,8 @@ const CoreMiddleware = (function(){ if (xhr_response.error && xhr_response.error.message){ var description = xhr_response.error.message; } + } else if (action.data.xhr){ + var description = action.data.xhr.status+' '+action.data.xhr.statusText; } else { var description = null; } diff --git a/src/js/services/spotify/actions.js b/src/js/services/spotify/actions.js index 756cc3b9..c8dbdf5d 100755 --- a/src/js/services/spotify/actions.js +++ b/src/js/services/spotify/actions.js @@ -58,12 +58,17 @@ const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) resolve(response) }, (xhr, status, error) => { - dispatch(uiActions.stopLoading(loader_key)) + dispatch(uiActions.stopLoading(loader_key)); + + // TODO: Rate limiting + if (xhr.status == 429){ + alert("You hit the Spotify API rate limiter"); + } // TODO: Instead of allowing request to fail before renewing the token, once refreshed // we should retry the original request(s) - if (xhr.responseJSON.error.message == 'The access token expired'){ - dispatch(refreshToken(dispatch, getState)) + if (xhr.responseJSON && xhr.responseJSON.error && xhr.responseJSON.error.message == 'The access token expired'){ + dispatch(refreshToken(dispatch, getState)); } reject({