Skip to content

Commit

Permalink
Gracefully handle case where no box art can be fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Jan 25, 2017
1 parent 497b450 commit a69b475
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
13 changes: 13 additions & 0 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ function showApps(host) {
console.log('Error! Failed to retrieve box art for app ID: ' + app.id + '. Returned value was: ' + failedPromise)
console.log('failed host object: ');
console.log(host.toString());

if ($('#game-' + app.id).length === 0) {
// double clicking the button will cause multiple box arts to appear.
// to mitigate this we ensure we don't add a duplicate.
// This isn't perfect: there's lots of RTTs before the logic prevents anything
$("#game-grid").append($("<div>", {html:$("<img \>", {src: "static/res/no_app_image.png", id: 'game-'+app.id, name: app.title }), class: 'box-art mdl-cell mdl-cell--3-col'}).append($("<span>", {html: app.title, class:"game-title"})));
$('#game-'+app.id).on('click', function () {
startGame(host, app.id);
});

// apply CSS stylization to indicate whether the app is active
stylizeBoxArt(host, app.id);
}
});
});
}, function (failedAppList) {
Expand Down
17 changes: 14 additions & 3 deletions static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,14 @@ NvHTTP.prototype = {

// TODO: unfortunately we do N lookups from storage cache, each of them filling up the memory cache.
// once the first round of calls are all made, each subsequent request hits this and returns from memory cache
if (this._memCachedBoxArtArray[appId] !== undefined) {
if (this._memCachedBoxArtArray[appId] === null) {
// This means a previous box art request failed, don't try again
return new Promise(function (resolve, reject) {
console.log('returning cached box art failure result');
reject(null);
return;
}.bind(this));
} else if (this._memCachedBoxArtArray[appId] !== undefined) {
return new Promise(function (resolve, reject) {
console.log('returning memory cached box art');
resolve(this._memCachedBoxArtArray[appId]);
Expand Down Expand Up @@ -392,9 +399,13 @@ NvHTTP.prototype = {
console.log('returning streamed box art');
resolve(streamedBoxArt);
return;
}.bind(this), function(error) {
// Cache the failure but not persistently
this._memCachedBoxArtArray[appId] = null;
console.log('box art request failed');
reject(error);
return;
}.bind(this));


}.bind(this));
}.bind(this));

Expand Down
Binary file added static/res/no_app_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a69b475

Please sign in to comment.