Skip to content

Commit a91b461

Browse files
committed
Fixed issue with not finding users
1 parent c75dbac commit a91b461

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

js/app.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var cachingData = new function () {
3737
};
3838

3939
// clears all the local storage items:
40-
self.clearCache = function() {
40+
self.clearCache = function () {
4141
console.log("clearing cache");
4242
storageAPI.clear();
4343
};
@@ -105,10 +105,18 @@ var drib = {
105105
this.req(yql, function (data) {
106106
console.log(data);
107107
$('#lookup-player').removeClass('error');
108+
// check to see if the user was found:
109+
if (data.query.results.message && data.query.results.message == 'Not found') {
110+
cachingData.clearCache();
111+
drib.showError("We're sorry, we couldn't find that username. We'll show you the popular shots in the meantime");
112+
drib.getPopular();
113+
return;
114+
}
108115
getShots.buildShots(data.query.results.json.shots);
109116

110117
});
111118
},
119+
112120
req:function (url, cbfunc) {
113121
var lastTimeChecked = cachingData.getLastTimeChecked(),
114122
cachedData = cachingData.getCachedShots(),
@@ -134,9 +142,11 @@ var drib = {
134142
OnSuccess(data);
135143
},
136144
error:function (x, t, m) {
145+
// automatically clear cache for any errors:
146+
cachingData.clearCache();
147+
137148
if (t === "timeout") {
138-
$('#lookup-player').removeClass('playerList').addClass('error');
139-
$('.subInfo').html("<span style='color:#ce4d73'>We're sorry, we couldn't find that username. We'll show you the popular shots in the meantime<span>");
149+
drib.showError("We're sorry, we couldn't find that username. We'll show you the popular shots in the meantime");
140150
console.log('timeout error');
141151
drib.getPopular();
142152
} else {
@@ -180,6 +190,13 @@ var drib = {
180190
}
181191
cbfunc(data);
182192
}
193+
},
194+
195+
showError:function (errorMessage) {
196+
$('#lookup-player').removeClass('playerList').addClass('error');
197+
$('.subInfo').html("<span style='color:#ce4d73'>" +
198+
errorMessage +
199+
"<span>");
183200
}
184201
};
185202

0 commit comments

Comments
 (0)