So I've been looking at a bunch of questions on callbacks, and I can't seem to wrap my brain around getting my own code to work properly. I am trying to check URLs with the Soundcloud API to make sure they direct to working sounds.
function urlOK(url){
SC.initialize({
client_id: 'my_client_id'
});
SC.resolve(url).catch(function(error) {
console.log(error.message);
return false; // have tried callback here
});
// also want to return true if no errors are found
}
function checkAllInput(){
if(urlOK(some_url){
// do more logic
}
}
With the code shown, urlOK of course blows past the resolve() call and "returns" false in the checkAllInput function. I have tried adding a callback function to urlOK in the spot indicated, and this correctly handled bad URL inputs. Good URL inputs did not "catch" though, and I am terribly confused as to how I should proceed.
I am happy to use jQuery, if it makes anything easier. :) I am also open to totally different approaches, and will answer questions as best as I can. Thank you for any help!