18
18
import android .os .Bundle ;
19
19
import android .os .Handler ;
20
20
import android .os .Message ;
21
+ import android .util .Log ;
21
22
import android .widget .Toast ;
22
23
23
24
@@ -82,7 +83,16 @@ public void handleMessage(Message msg) {
82
83
}
83
84
} else {
84
85
// incorrect format
85
- RestApi .this .onError ("Unknown format of data" );
86
+ Log .d ("RestApi" , data .toString ());
87
+ //RestApi.this.onError("Unknown format of data");
88
+ // we want to save the cache
89
+ if (RestApi .this .requestType .equalsIgnoreCase ("get" ) == true && RestApi .this .cachePolicy != RestCache .CachePolicy .IGNORE_CACHE ) {
90
+ RestCache .save (RestApi .this , data .trim ());
91
+ }
92
+
93
+ if (RestApi .this .cachePolicy != RestCache .CachePolicy .UPDATE_CACHE ) {
94
+ RestApi .this .onSuccess (data );
95
+ }
86
96
}
87
97
} catch (JSONException e ) {
88
98
e .printStackTrace ();
@@ -91,8 +101,8 @@ public void handleMessage(Message msg) {
91
101
}
92
102
} else if (b .containsKey ("error" ) == true ) {
93
103
RestApi .this .onError (b .getString ("error" ));
94
- } else if (b .containsKey ("statusCodeError" ) == true ) {
95
- RestApi .this .onStatusCodeError (b .getString ("statusCodeError" ));
104
+ } else if (b .containsKey ("statusCodeError" ) == true && b . containsKey ( "statusCodeErrorNumber" ) == true ) {
105
+ RestApi .this .onStatusCodeError (b .getInt ( "statusCodeErrorNumber" ), b . getString ("statusCodeError" ));
96
106
} else {
97
107
RestApi .this .onError ("Misconfigured code" );
98
108
}
@@ -208,7 +218,7 @@ public void onSuccess(Object obj) {
208
218
}
209
219
}
210
220
211
- public void onStatusCodeError (String data ) {
221
+ public void onStatusCodeError (int code , String data ) {
212
222
if (this .errorCallback != null ) {
213
223
this .errorCallback .error (data );
214
224
} else {
0 commit comments