Reducing opportunities for undefined variables; Origin-stamping errors
This commit is contained in:
5
src/js/bootstrap.js
vendored
5
src/js/bootstrap.js
vendored
@ -32,9 +32,10 @@ var initialState = {
|
|||||||
current_tracklist: [],
|
current_tracklist: [],
|
||||||
current_tltrack: false,
|
current_tltrack: false,
|
||||||
albums: {},
|
albums: {},
|
||||||
users: {},
|
artists: {},
|
||||||
playlists: {},
|
playlists: {},
|
||||||
artists: {}
|
users: {},
|
||||||
|
tracks: {}
|
||||||
},
|
},
|
||||||
ui: {
|
ui: {
|
||||||
slim_mode: false,
|
slim_mode: false,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
var coreActions = require('../core/actions')
|
||||||
var uiActions = require('../ui/actions')
|
var uiActions = require('../ui/actions')
|
||||||
var helpers = require('../../helpers')
|
var helpers = require('../../helpers')
|
||||||
|
|
||||||
@ -12,23 +13,31 @@ var helpers = require('../../helpers')
|
|||||||
const sendRequest = ( dispatch, getState, params ) => {
|
const sendRequest = ( dispatch, getState, params ) => {
|
||||||
return new Promise( (resolve, reject) => {
|
return new Promise( (resolve, reject) => {
|
||||||
|
|
||||||
var url = '//ws.audioscrobbler.com/2.0/?format=json&api_key=4320a3ef51c9b3d69de552ac083c55e3&'+params
|
|
||||||
|
|
||||||
var loader_key = helpers.generateGuid()
|
var loader_key = helpers.generateGuid()
|
||||||
dispatch(uiActions.startLoading(loader_key, 'lastfm_'+params))
|
dispatch(uiActions.startLoading(loader_key, 'lastfm_'+params))
|
||||||
|
|
||||||
$.ajax({
|
var config = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
cache: true,
|
cache: true,
|
||||||
url: url
|
url: '//ws.audioscrobbler.com/2.0/?format=json&api_key=4320a3ef51c9b3d69de552ac083c55e3&'+params
|
||||||
}).then(
|
}
|
||||||
|
|
||||||
|
$.ajax(config).then(
|
||||||
response => {
|
response => {
|
||||||
dispatch(uiActions.stopLoading(loader_key))
|
dispatch(uiActions.stopLoading(loader_key))
|
||||||
resolve(response)
|
resolve(response)
|
||||||
},
|
},
|
||||||
(xhr, status, error) => {
|
(xhr, status, error) => {
|
||||||
dispatch(uiActions.stopLoading(loader_key))
|
dispatch(uiActions.stopLoading(loader_key))
|
||||||
console.error( params+' failed', xhr.responseText)
|
dispatch(coreActions.handleException(
|
||||||
|
'LastFM: '+xhr.responseText,
|
||||||
|
{
|
||||||
|
config: config,
|
||||||
|
error: error,
|
||||||
|
status: status,
|
||||||
|
xhr: xhr
|
||||||
|
}
|
||||||
|
));
|
||||||
reject(error)
|
reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -146,7 +146,7 @@ const MopidyMiddleware = (function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
store.dispatch(coreActions.handleException(
|
store.dispatch(coreActions.handleException(
|
||||||
error.message,
|
'Mopidy: '+error.message,
|
||||||
error
|
error
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -331,7 +331,10 @@ const MopidyMiddleware = (function(){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Lookup failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Lookup failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -455,7 +458,10 @@ const MopidyMiddleware = (function(){
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Adding tracks failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Adding tracks failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -489,7 +495,10 @@ const MopidyMiddleware = (function(){
|
|||||||
}
|
}
|
||||||
store.dispatch(pusherActions.addQueueMetadata(tlids, action.from_uri))
|
store.dispatch(pusherActions.addQueueMetadata(tlids, action.from_uri))
|
||||||
} else {
|
} else {
|
||||||
store.dispatch(coreActions.handleException("Failed to add some tracks",response));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: Failed to add some tracks",
|
||||||
|
response
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the rest of our uris (if any)
|
// add the rest of our uris (if any)
|
||||||
@ -507,7 +516,10 @@ const MopidyMiddleware = (function(){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Adding tracks failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Adding tracks failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
@ -521,7 +533,10 @@ const MopidyMiddleware = (function(){
|
|||||||
// TODO: when complete, send event to confirm success/failure
|
// TODO: when complete, send event to confirm success/failure
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Reorder failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Reorder failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
@ -649,7 +664,10 @@ const MopidyMiddleware = (function(){
|
|||||||
continue_process();
|
continue_process();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
continue_process();
|
continue_process();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -713,7 +731,10 @@ const MopidyMiddleware = (function(){
|
|||||||
continue_process();
|
continue_process();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
continue_process();
|
continue_process();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -761,7 +782,10 @@ const MopidyMiddleware = (function(){
|
|||||||
continue_process();
|
continue_process();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
continue_process();
|
continue_process();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -803,7 +827,10 @@ const MopidyMiddleware = (function(){
|
|||||||
continue_process();
|
continue_process();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
continue_process();
|
continue_process();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -836,7 +863,10 @@ const MopidyMiddleware = (function(){
|
|||||||
process_albums();
|
process_albums();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
process_albums();
|
process_albums();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -884,7 +914,10 @@ const MopidyMiddleware = (function(){
|
|||||||
process_artists();
|
process_artists();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
process_artists();
|
process_artists();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -935,7 +968,10 @@ const MopidyMiddleware = (function(){
|
|||||||
process_playlists();
|
process_playlists();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
process_playlists();
|
process_playlists();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -996,7 +1032,10 @@ const MopidyMiddleware = (function(){
|
|||||||
finished();
|
finished();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
store.dispatch(coreActions.handleException((error.message ? error.message : "Search failed"),error));
|
store.dispatch(coreActions.handleException(
|
||||||
|
"Mopidy: "+(error.message ? error.message : "Search failed"),
|
||||||
|
error
|
||||||
|
));
|
||||||
finished();
|
finished();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -24,7 +24,7 @@ const PusherMiddleware = (function(){
|
|||||||
// error
|
// error
|
||||||
if (message.status == 0){
|
if (message.status == 0){
|
||||||
store.dispatch(coreActions.handleException(
|
store.dispatch(coreActions.handleException(
|
||||||
message.message,
|
'Pusher: '+message.message,
|
||||||
message
|
message
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ const PusherMiddleware = (function(){
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
store.dispatch(coreActions.handleException(
|
store.dispatch(coreActions.handleException(
|
||||||
'Pusher response received with no matching request',
|
'Pusher: Response received with no matching request',
|
||||||
message
|
message
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,8 +56,9 @@ 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))
|
||||||
dispatch(coreActions.handleException(
|
dispatch(coreActions.handleException(
|
||||||
xhr.responseJSON.error.message,
|
'Spotify: '+xhr.responseJSON.error.message,
|
||||||
{
|
{
|
||||||
|
source: 'spotify/actions.js/sendRequest',
|
||||||
config: config,
|
config: config,
|
||||||
xhr: xhr,
|
xhr: xhr,
|
||||||
status: status,
|
status: status,
|
||||||
@ -99,10 +100,6 @@ function getToken( dispatch, getState ){
|
|||||||
.then(
|
.then(
|
||||||
response => {
|
response => {
|
||||||
resolve(response.access_token)
|
resolve(response.access_token)
|
||||||
},
|
|
||||||
error => {
|
|
||||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
|
||||||
reject(error)
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -134,8 +131,9 @@ function refreshToken( dispatch, getState ){
|
|||||||
(xhr, status, error) => {
|
(xhr, status, error) => {
|
||||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||||
dispatch(coreActions.handleException(
|
dispatch(coreActions.handleException(
|
||||||
xhr.responseJSON.error_description,
|
'Spotify: '+xhr.responseJSON.error_description,
|
||||||
{
|
{
|
||||||
|
source: 'spotify/actions.js/refreshToken',
|
||||||
config: config,
|
config: config,
|
||||||
xhr: xhr,
|
xhr: xhr,
|
||||||
status: status,
|
status: status,
|
||||||
@ -146,7 +144,7 @@ function refreshToken( dispatch, getState ){
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -158,8 +156,16 @@ function refreshToken( dispatch, getState ){
|
|||||||
response => {
|
response => {
|
||||||
if (response.type == 'error'){
|
if (response.type == 'error'){
|
||||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||||
dispatch(uiActions.createNotification(response.message,'bad'))
|
dispatch(coreActions.handleException(
|
||||||
console.error('Could not refresh token', response)
|
'Spotify: '+response.message,
|
||||||
|
{
|
||||||
|
source: 'spotify/actions.js/refreshToken',
|
||||||
|
config: config,
|
||||||
|
xhr: xhr,
|
||||||
|
status: status,
|
||||||
|
error: error
|
||||||
|
}
|
||||||
|
))
|
||||||
reject(response)
|
reject(response)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -177,8 +183,16 @@ function refreshToken( dispatch, getState ){
|
|||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||||
dispatch(uiActions.createNotification('Could not refresh token','bad'))
|
dispatch(coreActions.handleException(
|
||||||
console.error('Could not refresh token', error)
|
'Spotify: Could not refresh token',
|
||||||
|
{
|
||||||
|
source: 'spotify/actions.js/refreshToken',
|
||||||
|
config: config,
|
||||||
|
xhr: xhr,
|
||||||
|
status: status,
|
||||||
|
error: error
|
||||||
|
}
|
||||||
|
))
|
||||||
reject(error)
|
reject(error)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user