package com.facebook; import com.facebook.internal.Logger; import com.facebook.internal.Utility; import com.ubt.jimu.diy.model.CategoryModel; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.List; import java.util.Locale; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; /* loaded from: classes.dex */ public class GraphResponse { private final HttpURLConnection a; private final JSONObject b; private final FacebookRequestError c; public enum PagingDirection { NEXT, PREVIOUS } GraphResponse(GraphRequest graphRequest, HttpURLConnection httpURLConnection, String str, JSONObject jSONObject) { this(graphRequest, httpURLConnection, str, jSONObject, null, null); } public final FacebookRequestError a() { return this.c; } public final JSONObject b() { return this.b; } public String toString() { String str; try { Locale locale = Locale.US; Object[] objArr = new Object[1]; objArr[0] = Integer.valueOf(this.a != null ? this.a.getResponseCode() : 200); str = String.format(locale, "%d", objArr); } catch (IOException unused) { str = CategoryModel.unknown; } return "{Response: responseCode: " + str + ", graphObject: " + this.b + ", error: " + this.c + "}"; } GraphResponse(GraphRequest graphRequest, HttpURLConnection httpURLConnection, String str, JSONArray jSONArray) { this(graphRequest, httpURLConnection, str, null, jSONArray, null); } static List a(HttpURLConnection httpURLConnection, GraphRequestBatch graphRequestBatch) { InputStream inputStream = null; try { inputStream = httpURLConnection.getResponseCode() >= 400 ? httpURLConnection.getErrorStream() : httpURLConnection.getInputStream(); return a(inputStream, httpURLConnection, graphRequestBatch); } catch (FacebookException e) { Logger.a(LoggingBehavior.REQUESTS, "Response", "Response : %s", e); return a(graphRequestBatch, httpURLConnection, e); } catch (Exception e2) { Logger.a(LoggingBehavior.REQUESTS, "Response", "Response : %s", e2); return a(graphRequestBatch, httpURLConnection, new FacebookException(e2)); } finally { Utility.a((Closeable) inputStream); } } GraphResponse(GraphRequest graphRequest, HttpURLConnection httpURLConnection, FacebookRequestError facebookRequestError) { this(graphRequest, httpURLConnection, null, null, null, facebookRequestError); } GraphResponse(GraphRequest graphRequest, HttpURLConnection httpURLConnection, String str, JSONObject jSONObject, JSONArray jSONArray, FacebookRequestError facebookRequestError) { this.a = httpURLConnection; this.b = jSONObject; this.c = facebookRequestError; } static List a(InputStream inputStream, HttpURLConnection httpURLConnection, GraphRequestBatch graphRequestBatch) throws FacebookException, JSONException, IOException { String a = Utility.a(inputStream); Logger.a(LoggingBehavior.INCLUDE_RAW_RESPONSES, "Response", "Response (raw)\n Size: %d\n Response:\n%s\n", Integer.valueOf(a.length()), a); return a(a, httpURLConnection, graphRequestBatch); } static List a(String str, HttpURLConnection httpURLConnection, GraphRequestBatch graphRequestBatch) throws FacebookException, JSONException, IOException { List a = a(httpURLConnection, graphRequestBatch, new JSONTokener(str).nextValue()); Logger.a(LoggingBehavior.REQUESTS, "Response", "Response\n Id: %s\n Size: %d\n Responses:\n%s\n", graphRequestBatch.j(), Integer.valueOf(str.length()), a); return a; } /* JADX WARN: Removed duplicated region for block: B:11:0x0056 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private static java.util.List a(java.net.HttpURLConnection r7, java.util.List r8, java.lang.Object r9) throws com.facebook.FacebookException, org.json.JSONException { /* int r0 = r8.size() java.util.ArrayList r1 = new java.util.ArrayList r1.(r0) r2 = 0 r3 = 1 if (r0 != r3) goto L51 java.lang.Object r3 = r8.get(r2) com.facebook.GraphRequest r3 = (com.facebook.GraphRequest) r3 org.json.JSONObject r4 = new org.json.JSONObject // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 r4.() // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 java.lang.String r5 = "body" r4.put(r5, r9) // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 if (r7 == 0) goto L24 int r5 = r7.getResponseCode() // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 goto L26 L24: r5 = 200(0xc8, float:2.8E-43) L26: java.lang.String r6 = "code" r4.put(r6, r5) // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 org.json.JSONArray r5 = new org.json.JSONArray // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 r5.() // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 r5.put(r4) // Catch: java.io.IOException -> L34 org.json.JSONException -> L43 goto L52 L34: r4 = move-exception com.facebook.GraphResponse r5 = new com.facebook.GraphResponse com.facebook.FacebookRequestError r6 = new com.facebook.FacebookRequestError r6.(r7, r4) r5.(r3, r7, r6) r1.add(r5) goto L51 L43: r4 = move-exception com.facebook.GraphResponse r5 = new com.facebook.GraphResponse com.facebook.FacebookRequestError r6 = new com.facebook.FacebookRequestError r6.(r7, r4) r5.(r3, r7, r6) r1.add(r5) L51: r5 = r9 L52: boolean r3 = r5 instanceof org.json.JSONArray if (r3 == 0) goto L97 org.json.JSONArray r5 = (org.json.JSONArray) r5 int r3 = r5.length() if (r3 != r0) goto L97 L5e: int r0 = r5.length() if (r2 >= r0) goto L96 java.lang.Object r0 = r8.get(r2) com.facebook.GraphRequest r0 = (com.facebook.GraphRequest) r0 java.lang.Object r3 = r5.get(r2) // Catch: com.facebook.FacebookException -> L76 org.json.JSONException -> L85 com.facebook.GraphResponse r3 = a(r0, r7, r3, r9) // Catch: com.facebook.FacebookException -> L76 org.json.JSONException -> L85 r1.add(r3) // Catch: com.facebook.FacebookException -> L76 org.json.JSONException -> L85 goto L93 L76: r3 = move-exception com.facebook.GraphResponse r4 = new com.facebook.GraphResponse com.facebook.FacebookRequestError r6 = new com.facebook.FacebookRequestError r6.(r7, r3) r4.(r0, r7, r6) r1.add(r4) goto L93 L85: r3 = move-exception com.facebook.GraphResponse r4 = new com.facebook.GraphResponse com.facebook.FacebookRequestError r6 = new com.facebook.FacebookRequestError r6.(r7, r3) r4.(r0, r7, r6) r1.add(r4) L93: int r2 = r2 + 1 goto L5e L96: return r1 L97: com.facebook.FacebookException r7 = new com.facebook.FacebookException java.lang.String r8 = "Unexpected number of results" r7.(r8) throw r7 */ throw new UnsupportedOperationException("Method not decompiled: com.facebook.GraphResponse.a(java.net.HttpURLConnection, java.util.List, java.lang.Object):java.util.List"); } private static GraphResponse a(GraphRequest graphRequest, HttpURLConnection httpURLConnection, Object obj, Object obj2) throws JSONException { if (obj instanceof JSONObject) { JSONObject jSONObject = (JSONObject) obj; FacebookRequestError checkResponseAndCreateError = FacebookRequestError.checkResponseAndCreateError(jSONObject, obj2, httpURLConnection); if (checkResponseAndCreateError != null) { if (checkResponseAndCreateError.getErrorCode() == 190 && Utility.a(graphRequest.c())) { AccessToken.setCurrentAccessToken(null); } return new GraphResponse(graphRequest, httpURLConnection, checkResponseAndCreateError); } Object a = Utility.a(jSONObject, "body", "FACEBOOK_NON_JSON_RESULT"); if (a instanceof JSONObject) { return new GraphResponse(graphRequest, httpURLConnection, a.toString(), (JSONObject) a); } if (a instanceof JSONArray) { return new GraphResponse(graphRequest, httpURLConnection, a.toString(), (JSONArray) a); } obj = JSONObject.NULL; } if (obj == JSONObject.NULL) { return new GraphResponse(graphRequest, httpURLConnection, obj.toString(), (JSONObject) null); } throw new FacebookException("Got unexpected object type in response, class: " + obj.getClass().getSimpleName()); } static List a(List list, HttpURLConnection httpURLConnection, FacebookException facebookException) { int size = list.size(); ArrayList arrayList = new ArrayList(size); for (int i = 0; i < size; i++) { arrayList.add(new GraphResponse(list.get(i), httpURLConnection, new FacebookRequestError(httpURLConnection, facebookException))); } return arrayList; } }