Reducing opportunities for undefined variables; Origin-stamping errors

This commit is contained in:
James Barnsley
2017-09-25 20:22:48 +13:00
parent 60a560f4b3
commit beafc9e2a8
5 changed files with 101 additions and 38 deletions

View File

@ -1,4 +1,5 @@
var coreActions = require('../core/actions')
var uiActions = require('../ui/actions')
var helpers = require('../../helpers')
@ -10,25 +11,33 @@ var helpers = require('../../helpers')
* @param endpoint params = the url params to send
**/
const sendRequest = ( dispatch, getState, params ) => {
return new Promise( (resolve, reject) => {
var url = '//ws.audioscrobbler.com/2.0/?format=json&api_key=4320a3ef51c9b3d69de552ac083c55e3&'+params
return new Promise( (resolve, reject) => {
var loader_key = helpers.generateGuid()
dispatch(uiActions.startLoading(loader_key, 'lastfm_'+params))
$.ajax({
method: 'GET',
cache: true,
url: url
}).then(
var config = {
method: 'GET',
cache: true,
url: '//ws.audioscrobbler.com/2.0/?format=json&api_key=4320a3ef51c9b3d69de552ac083c55e3&'+params
}
$.ajax(config).then(
response => {
dispatch(uiActions.stopLoading(loader_key))
resolve(response)
},
(xhr, status, error) => {
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)
}
)