Handle bad rdio urls

This commit is contained in:
Jonathan Cremin 2014-12-07 18:33:55 +00:00
parent e5a69d684e
commit 7468cc4ea6
2 changed files with 30 additions and 22 deletions

View file

@ -18,7 +18,6 @@ module.exports.lookupId = function(id, type, cc) {
if (id.match(/^[a-z]{2}/)) {
cc = id.substr(0,2);
id = id.substr(2);
console.log(id)
}
var path = "/lookup?id=" + id;

View file

@ -74,11 +74,19 @@ module.exports.parseUrl = function(url) {
url: parsed.path,
};
} else {
return;
var error = new Error("Not Found");
error.status = 404;
deferred.reject(error);
}
rdio.api("", "", data, function(err, results) {
var result = JSON.parse(results).result;
var results = JSON.parse(results);
var result = results.result;
if (!result || results.status != "ok") {
var error = new Error("Not Found");
error.status = 404;
deferred.reject(error);
} else {
var parsed = parse(result.shortUrl)
var id = parsed.path.replace("/x/", "").replace("/", "");
var type = result.album ? "track" : "album";
@ -100,6 +108,7 @@ module.exports.parseUrl = function(url) {
};
}
deferred.resolve(item);
}
});
return deferred.promise;
};