diff --git a/lib/services/spotify.js b/lib/services/spotify.js index 64e5a61..966e441 100644 --- a/lib/services/spotify.js +++ b/lib/services/spotify.js @@ -13,8 +13,10 @@ module.exports.match = function(url, type) { module.exports.lookupId = function(id, type) { var deferred = Q.defer(); spotify.lookup({id: id, type: type}, function(err, data) { - if ( err ) { - console.log('Error occurred: ' + err); + if ( err || data.error) { + var error = new Error("Not Found"); + error.status = 404; + deferred.reject(error); return; } diff --git a/routes/share.js b/routes/share.js index c0c6de0..e2466e6 100644 --- a/routes/share.js +++ b/routes/share.js @@ -60,11 +60,14 @@ module.exports = function(req, res, next) { cache[serviceId][type + "-" + itemId] = items; res.render(type, {page: type, items: items}); }); - }, function(err) { - var error = new Error("An unexpected error happenend") - if (err.code == "ETIMEDOUT") { + }, function(error) { + console.log(error) + if (error.code == "ETIMEDOUT") { error = new Error("Error talking to music service"); error.status = "502"; + } else if (!error.status) { + error = new Error("An unexpected error happenend"); + error.status = 500; } next(error); });