Handling exceptions corrupted state, now fixed

This commit is contained in:
James Barnsley
2017-09-28 08:39:44 +13:00
parent beb01d5f3f
commit fec829cc33
4 changed files with 48 additions and 26 deletions

View File

@ -17,7 +17,17 @@ export function getBroadcasts(){
})
},
(xhr, status, error) => {
console.error('Could not fetch broadcasts from GitHub')
dispatch(
handleException(
'Could not fetch broadcasts from GitHub',
{
config: config,
xhr: xhr,
status: status,
error: error
}
)
);
}
)
}

View File

@ -19,28 +19,36 @@ const CoreMiddleware = (function(){
switch(action.type){
case 'HANDLE_EXCEPTION':
var state = Object.assign({}, store.getState());
var message = action.message;
var state = store.getState();
var exported_state = {
core: Object.assign({},state.core),
ui: Object.assign({},state.ui),
spotify: Object.assign({},state.spotify),
mopidy: Object.assign({},state.mopidy),
pusher: Object.assign({},state.pusher)
}
// Strip out non-essential store info
delete state.core.albums
delete state.core.artists
delete state.core.playlists
delete state.core.users
delete state.core.queue_metadata
delete state.core.current_tracklist
delete state.spotify.library_albums
delete state.spotify.library_artists
delete state.spotify.library_playlists
delete state.spotify.autocomplete_results
delete state.mopidy.library_albums
delete state.mopidy.library_artists
delete state.mopidy.library_playlists
delete exported_state.core.albums
delete exported_state.core.artists
delete exported_state.core.playlists
delete exported_state.core.users
delete exported_state.core.queue_metadata
delete exported_state.core.current_tracklist
delete exported_state.spotify.library_albums
delete exported_state.spotify.library_artists
delete exported_state.spotify.library_playlists
delete exported_state.spotify.autocomplete_results
delete exported_state.mopidy.library_albums
delete exported_state.mopidy.library_artists
delete exported_state.mopidy.library_playlists
var data = Object.assign(
{},
action.data,
{
state: state
state: exported_state
}
);
@ -51,7 +59,12 @@ const CoreMiddleware = (function(){
}
);
store.dispatch(uiActions.createNotification(action.message,'bad'));
var xhr_response = JSON.parse(action.data.xhr.responseText);
if (xhr_response.error && xhr_response.error.message){
message = message +": "+ xhr_response.error.message;
}
store.dispatch(uiActions.createNotification(message,'bad'));
console.error(action.message, data);
break;

View File

@ -68,7 +68,7 @@ const sendRequest = ( dispatch, getState, endpoint, method = 'GET', data = false
xhr: xhr,
status: status,
error: error
})
});
}
)
},

View File

@ -76,37 +76,36 @@ const SpotifyMiddleware = (function(){
ReactGA.event({ category: 'Spotify', action: 'Recommendations', label: action.seeds_uris.join(',') })
}
next(action)
break
break;
case 'SPOTIFY_USER_LOADED':
if (action.data) ReactGA.event({ category: 'User', action: 'Load', label: action.data.uri })
next(action)
break
break;
case 'SPOTIFY_CREATE_PLAYLIST':
store.dispatch( spotifyActions.createPlaylist( action.name, action.description, action.is_private, action.is_collaborative ))
break
break;
case 'SPOTIFY_REMOVE_PLAYLIST_TRACKS':
var playlist = Object.assign({},state.core.playlists[action.key]);
store.dispatch( spotifyActions.deleteTracksFromPlaylist( playlist.uri, playlist.snapshot_id, action.tracks_indexes ))
break
break;
case 'SPOTIFY_ADD_PLAYLIST_TRACKS':
store.dispatch( spotifyActions.addTracksToPlaylist( action.key, action.tracks_uris ))
break
break;
case 'SPOTIFY_REORDER_PLAYLIST_TRACKS':
store.dispatch( spotifyActions.reorderPlaylistTracks( action.key, action.range_start, action.range_length, action.insert_before, action.snapshot_id ))
break
break;
case 'SPOTIFY_SAVE_PLAYLIST':
store.dispatch( spotifyActions.savePlaylist( action.key, action.name, action.description, action.is_public, action.is_collaborative ))
break
break;
case 'SPOTIFY_NEW_RELEASES_LOADED':
store.dispatch({