From 15712f9482596d8fa0a8176b1db51e122b947076 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sun, 28 Dec 2014 23:19:18 +0000 Subject: [PATCH] Handle non-album/track ids in GPM, 404 xbox --- lib/services/google/index.js | 8 +++++++- lib/services/xbox/index.js | 4 ++++ routes/search.js | 4 ++-- views/share.jsx | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/services/google/index.js b/lib/services/google/index.js index d73827e..61a7bef 100644 --- a/lib/services/google/index.js +++ b/lib/services/google/index.js @@ -28,7 +28,11 @@ module.exports.parseUrl = function(url) { var id = parts[2]; var artist = decodeURIComponent(parts[3]); var album = decodeURIComponent(parts[4]); - + + if (type != "album" && type != "track") { + return false; + } + if (id.length > 0) { return {id: id, type: type}; } else { @@ -39,6 +43,7 @@ module.exports.parseUrl = function(url) { var type = matches[1][0] == "T" ? "track" : "album"; return module.exports.lookupId(matches[1], type); } + return false; }) } @@ -105,6 +110,7 @@ module.exports.search = function(data) { } return pm.searchAsync(query, 5).then(function(result) { + if (!result.entries) { var matches = album.match(/^[^\(\[]+/); if (matches[0] && matches[0] != album) { diff --git a/lib/services/xbox/index.js b/lib/services/xbox/index.js index cad53fa..fed0e9c 100644 --- a/lib/services/xbox/index.js +++ b/lib/services/xbox/index.js @@ -72,6 +72,8 @@ module.exports.lookupId = function(id, type) { var path = "/" + id + "/lookup"; return request.get(apiRoot + path).set("Authorization", "Bearer " + access_token).promise().then(function(res) { return formatResponse(res); + }, function(res) { + return {service: "xbox"}; }); }); }; @@ -92,6 +94,8 @@ module.exports.search = function(data) { var path = "/music/search?q=" + encodeURIComponent(query) + "&filters=" + type + "s"; return request.get(apiRoot + path).set("Authorization", "Bearer " + access_token).promise().then(function(res) { return formatResponse(res); + }, function(res) { + return {service: "xbox"}; }); }); }; diff --git a/routes/search.js b/routes/search.js index 61b977b..a35921a 100644 --- a/routes/search.js +++ b/routes/search.js @@ -46,9 +46,9 @@ module.exports = function(req, res, next) { error = new Error("An unexpected error happenend"); error.status = 500; next(error); - } else if (error.status == 404){ - res.json({error:{message:"No match found for url"}}); } + + res.json({error:{message:"No match found for url"}}); }); break; } diff --git a/views/share.jsx b/views/share.jsx index 0100582..f41324f 100644 --- a/views/share.jsx +++ b/views/share.jsx @@ -133,6 +133,7 @@ module.exports = React.createClass({ getShares(); } + // Temporary until websockets implementation this.state.interval = setInterval(function() { if (!complete) { getShares();