File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/com/loopj/android/http Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -78,4 +78,25 @@ protected void handleSuccessMessage(String responseBody) {
7878 protected Object parseResponse (String responseBody ) throws JSONException {
7979 return new JSONTokener (responseBody ).nextValue ();
8080 }
81+
82+ /**
83+ * Handle cases where a failure is returned as JSON
84+ */
85+ public void onFailure (Throwable e , JSONObject errorResponse ) {}
86+ public void onFailure (Throwable e , JSONArray errorResponse ) {}
87+
88+ @ Override
89+ protected void handleFailureMessage (Throwable e , String responseBody ) {
90+ super .handleFailureMessage (e , responseBody );
91+ try {
92+ Object jsonResponse = parseResponse (responseBody );
93+ if (jsonResponse instanceof JSONObject ) {
94+ onFailure (e , (JSONObject )jsonResponse );
95+ } else if (jsonResponse instanceof JSONArray ) {
96+ onFailure (e , (JSONArray )jsonResponse );
97+ }
98+ } catch (JSONException ex ) {
99+ onFailure (e , responseBody );
100+ }
101+ }
81102}
You can’t perform that action at this time.
0 commit comments