Skip to content

Commit 47c089b

Browse files
committed
when there's a status code error, return it in the callback function, and when the data format is unknown, still call the success callback (rather than the error one)
1 parent 0accc68 commit 47c089b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

com/manavo/rest/RestApi.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.os.Bundle;
1919
import android.os.Handler;
2020
import android.os.Message;
21+
import android.util.Log;
2122
import android.widget.Toast;
2223

2324

@@ -82,7 +83,16 @@ public void handleMessage(Message msg) {
8283
}
8384
} else {
8485
// 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+
}
8696
}
8797
} catch (JSONException e) {
8898
e.printStackTrace();
@@ -91,8 +101,8 @@ public void handleMessage(Message msg) {
91101
}
92102
} else if (b.containsKey("error") == true) {
93103
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"));
96106
} else {
97107
RestApi.this.onError("Misconfigured code");
98108
}
@@ -208,7 +218,7 @@ public void onSuccess(Object obj) {
208218
}
209219
}
210220

211-
public void onStatusCodeError(String data) {
221+
public void onStatusCodeError(int code, String data) {
212222
if (this.errorCallback != null) {
213223
this.errorCallback.error(data);
214224
} else {

0 commit comments

Comments
 (0)