package com.ss.android.ugc.aweme.net;

import X.C23868bx;
import X.C51409fH;
import X.C51779fs;
import android.net.Uri;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.retrofit2.client.Request;
import java.util.Map;

public class ApiVerifyInterceptor implements C23868bx {
    public static final boolean LIZ = false;

    static {
        Covode.recordClassIndex(94628);
    }

    /* JADX WARNING: Removed duplicated region for block: B:34:0x0087 A[EDGE_INSN: B:61:0x0087->B:34:0x0087 ?: BREAK  
    EDGE_INSN: B:62:0x0087->B:34:0x0087 ?: BREAK  ] */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x0095  */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x00b6 A[LOOP:0: B:30:0x007b->B:42:0x00b6, LOOP_END] */
    /* JADX WARNING: Removed duplicated region for block: B:58:0x0133  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public X.C51029ef intercept(X.C51489fP r10) {
        /*
            r9 = this;
            com.bytedance.retrofit2.client.Request r6 = r10.LIZ()
            r8 = 0
            r7 = 0
            X.9ef r3 = r10.LIZ(r6)     // Catch:{ JMC -> 0x0054 }
            boolean r1 = r6.isResponseStreaming()     // Catch:{ JMC -> 0x0058 }
            r0 = 1
            if (r1 == 0) goto L_0x0012
            goto L_0x0053
        L_0x0012:
            X.9eE r1 = r3.LIZ     // Catch:{ JMC -> 0x0058 }
            java.lang.String r0 = "Content-Type"
            X.8BD r2 = r1.LIZ(r0)     // Catch:{ JMC -> 0x0058 }
            java.lang.String r1 = r6.getPath()     // Catch:{ JMC -> 0x0058 }
            if (r2 == 0) goto L_0x0053
            boolean r0 = android.text.TextUtils.isEmpty(r1)     // Catch:{ JMC -> 0x0058 }
            if (r0 != 0) goto L_0x0037
            java.lang.String r0 = "/effect/api"
            boolean r0 = r1.contains(r0)     // Catch:{ JMC -> 0x0058 }
            if (r0 != 0) goto L_0x0053
            java.lang.String r0 = "/model/api"
            boolean r0 = r1.contains(r0)     // Catch:{ JMC -> 0x0058 }
            if (r0 == 0) goto L_0x0037
            goto L_0x0053
        L_0x0037:
            java.lang.String r1 = r2.LIZIZ     // Catch:{ JMC -> 0x0058 }
            boolean r0 = android.text.TextUtils.isEmpty(r1)     // Catch:{ JMC -> 0x0058 }
            if (r0 != 0) goto L_0x0048
            java.lang.String r0 = "json"
            boolean r0 = r1.contains(r0)     // Catch:{ JMC -> 0x0058 }
            if (r0 != 0) goto L_0x0048
            goto L_0x0053
        L_0x0048:
            java.lang.String r0 = r6.getUrl()     // Catch:{ JMC -> 0x0058 }
            X.9fk r2 = com.ss.android.ugc.aweme.net.interceptor.ResponseExtraParser.LIZ(r0, r3)     // Catch:{ JMC -> 0x0058 }
            if (r2 != 0) goto L_0x0077
            return r3
        L_0x0053:
            return r3
        L_0x0054:
            r0 = move-exception
            r3 = r7
            r7 = r0
            goto L_0x0059
        L_0x0058:
            r7 = move-exception
        L_0x0059:
            X.9fy r4 = new X.9fy
            r4.<init>()
            int r0 = r7.getErrorCode()
            r4.LIZ = r0
            java.lang.String r0 = r7.getErrorMsg()
            r4.LIZIZ = r0
            java.lang.String r0 = r7.getPrompt()
            r4.LIZJ = r0
            X.9fk r2 = new X.9fk
            r0 = -1
            r2.<init>(r4, r0)
        L_0x0077:
            X.9fj r1 = X.C51689fj.LIZ()
        L_0x007b:
            X.9fs r5 = r1.LIZ(r2, r6, r3)
            boolean r0 = r5.LIZIZ
            if (r0 != 0) goto L_0x0087
            X.9fr r0 = r1.LIZIZ
            if (r0 != 0) goto L_0x00b6
        L_0x0087:
            boolean r0 = r5.LIZ
            if (r0 == 0) goto L_0x0133
            java.lang.String r0 = r6.getUrl()
            boolean r0 = android.text.TextUtils.isEmpty(r0)
            if (r0 != 0) goto L_0x0133
            java.util.HashMap r3 = new java.util.HashMap
            r3.<init>()
            java.util.List r0 = r6.getHeaders()
            java.util.Iterator r2 = r0.iterator()
        L_0x00a2:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x00b9
            java.lang.Object r0 = r2.next()
            X.8BD r0 = (X.AnonymousClass8BD) r0
            java.lang.String r1 = r0.LIZ
            java.lang.String r0 = r0.LIZIZ
            r3.put(r1, r0)
            goto L_0x00a2
        L_0x00b6:
            X.9fr r1 = r1.LIZIZ
            goto L_0x007b
        L_0x00b9:
            com.ss.android.ugc.aweme.IApiGuardService r1 = com.ss.android.ugc.aweme.account.apiguard.ApiGuardService.createIApiGuardServicebyMonsterPlugin(r8)
            X.9fA r0 = new X.9fA
            r0.<init>(r6)
            java.util.Map r0 = r1.appendHeaders(r0)
            if (r0 == 0) goto L_0x00e8
            java.util.Set r0 = r0.entrySet()
            java.util.Iterator r2 = r0.iterator()
        L_0x00d0:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x00e8
            java.lang.Object r0 = r2.next()
            java.util.Map$Entry r0 = (java.util.Map.Entry) r0
            java.lang.Object r1 = r0.getKey()
            java.lang.Object r0 = r0.getValue()
            r3.put(r1, r0)
            goto L_0x00d0
        L_0x00e8:
            java.util.ArrayList r4 = new java.util.ArrayList
            r4.<init>()
            java.util.Set r0 = r3.entrySet()
            java.util.Iterator r3 = r0.iterator()
        L_0x00f5:
            boolean r0 = r3.hasNext()
            if (r0 == 0) goto L_0x0116
            java.lang.Object r0 = r3.next()
            java.util.Map$Entry r0 = (java.util.Map.Entry) r0
            X.8BD r2 = new X.8BD
            java.lang.Object r1 = r0.getKey()
            java.lang.String r1 = (java.lang.String) r1
            java.lang.Object r0 = r0.getValue()
            java.lang.String r0 = (java.lang.String) r0
            r2.<init>(r1, r0)
            r4.add(r2)
            goto L_0x00f5
        L_0x0116:
            X.9fH r1 = r6.newBuilder()
            java.lang.String r0 = r6.getUrl()
            r1.LIZ(r0)
            com.bytedance.retrofit2.client.Request r1 = r1.LIZ()
            java.util.Map<java.lang.String, java.lang.String> r0 = r5.LIZJ
            if (r0 != 0) goto L_0x012e
        L_0x0129:
            X.9ef r0 = r10.LIZ(r1)
            return r0
        L_0x012e:
            com.bytedance.retrofit2.client.Request r1 = r9.LIZ(r1, r5)
            goto L_0x0129
        L_0x0133:
            if (r7 != 0) goto L_0x0136
            return r3
        L_0x0136:
            throw r7
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.net.ApiVerifyInterceptor.intercept(X.9fP):X.9ef");
    }

    private Request LIZ(Request request, C51779fs r7) {
        Uri.Builder buildUpon = Uri.parse(request.getUrl()).buildUpon();
        for (Map.Entry next : r7.LIZJ.entrySet()) {
            if (!TextUtils.isEmpty((CharSequence) next.getKey()) && !TextUtils.isEmpty((CharSequence) next.getValue())) {
                buildUpon.appendQueryParameter((String) next.getKey(), (String) next.getValue());
            }
        }
        C51409fH newBuilder = request.newBuilder();
        newBuilder.LIZ(buildUpon.build().toString());
        return newBuilder.LIZ();
    }
}
