@@ -37,7 +37,7 @@ var cachingData = new function () {
37
37
} ;
38
38
39
39
// clears all the local storage items:
40
- self . clearCache = function ( ) {
40
+ self . clearCache = function ( ) {
41
41
console . log ( "clearing cache" ) ;
42
42
storageAPI . clear ( ) ;
43
43
} ;
@@ -105,10 +105,18 @@ var drib = {
105
105
this . req ( yql , function ( data ) {
106
106
console . log ( data ) ;
107
107
$ ( '#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
+ }
108
115
getShots . buildShots ( data . query . results . json . shots ) ;
109
116
110
117
} ) ;
111
118
} ,
119
+
112
120
req :function ( url , cbfunc ) {
113
121
var lastTimeChecked = cachingData . getLastTimeChecked ( ) ,
114
122
cachedData = cachingData . getCachedShots ( ) ,
@@ -134,9 +142,11 @@ var drib = {
134
142
OnSuccess ( data ) ;
135
143
} ,
136
144
error :function ( x , t , m ) {
145
+ // automatically clear cache for any errors:
146
+ cachingData . clearCache ( ) ;
147
+
137
148
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" ) ;
140
150
console . log ( 'timeout error' ) ;
141
151
drib . getPopular ( ) ;
142
152
} else {
@@ -180,6 +190,13 @@ var drib = {
180
190
}
181
191
cbfunc ( data ) ;
182
192
}
193
+ } ,
194
+
195
+ showError :function ( errorMessage ) {
196
+ $ ( '#lookup-player' ) . removeClass ( 'playerList' ) . addClass ( 'error' ) ;
197
+ $ ( '.subInfo' ) . html ( "<span style='color:#ce4d73'>" +
198
+ errorMessage +
199
+ "<span>" ) ;
183
200
}
184
201
} ;
185
202
0 commit comments