Better handling of invalid ids

This commit is contained in:
Jonathan Cremin 2014-12-05 18:03:45 +00:00
parent c8eb31116c
commit a33570e1d0
2 changed files with 10 additions and 5 deletions

View file

@ -13,8 +13,10 @@ module.exports.match = function(url, type) {
module.exports.lookupId = function(id, type) { module.exports.lookupId = function(id, type) {
var deferred = Q.defer(); var deferred = Q.defer();
spotify.lookup({id: id, type: type}, function(err, data) { spotify.lookup({id: id, type: type}, function(err, data) {
if ( err ) { if ( err || data.error) {
console.log('Error occurred: ' + err); var error = new Error("Not Found");
error.status = 404;
deferred.reject(error);
return; return;
} }

View file

@ -60,11 +60,14 @@ module.exports = function(req, res, next) {
cache[serviceId][type + "-" + itemId] = items; cache[serviceId][type + "-" + itemId] = items;
res.render(type, {page: type, items: items}); res.render(type, {page: type, items: items});
}); });
}, function(err) { }, function(error) {
var error = new Error("An unexpected error happenend") console.log(error)
if (err.code == "ETIMEDOUT") { if (error.code == "ETIMEDOUT") {
error = new Error("Error talking to music service"); error = new Error("Error talking to music service");
error.status = "502"; error.status = "502";
} else if (!error.status) {
error = new Error("An unexpected error happenend");
error.status = 500;
} }
next(error); next(error);
}); });