package h5;

import A6.n;
import E6.d;
import F7.C0133q;
import F7.T;
import G6.i;
import O6.p;
import W4.e;
import X4.c;
import Z6.InterfaceC0382w;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.data.model.response.ErrorResponse;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.CancellationException;
import k7.D;
import k7.s;
import n4.u0;
import x7.C1731g;

/* JADX INFO: renamed from: h5.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1032a extends i implements p {

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f13420u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public /* synthetic */ Object f13421v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final /* synthetic */ i f13422w;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public C1032a(p pVar, d dVar) {
        super(2, dVar);
        this.f13422w = (i) pVar;
    }

    @Override // O6.p
    public final Object k(Object obj, Object obj2) {
        return ((C1032a) m((d) obj2, (InterfaceC0382w) obj)).p(n.f457a);
    }

    /* JADX WARN: Type inference failed for: r1v0, types: [G6.i, O6.p] */
    @Override // G6.a
    public final d m(d dVar, Object obj) {
        C1032a c1032a = new C1032a(this.f13422w, dVar);
        c1032a.f13421v = obj;
        return c1032a;
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x00ab A[Catch: all -> 0x00b8, TRY_ENTER, TryCatch #2 {all -> 0x00b8, blocks: (B:35:0x0078, B:37:0x007e, B:39:0x008d, B:41:0x0097, B:48:0x00a5, B:51:0x00ad, B:50:0x00ab), top: B:91:0x0078 }] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x00a5 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r1v6, types: [G6.i, O6.p] */
    @Override // G6.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object p(Object obj) throws Exception {
        String strN0;
        Object objJ;
        D d8;
        String str;
        F6.a aVar = F6.a.f2580q;
        int i = this.f13420u;
        try {
            if (i == 0) {
                C1.N(obj);
                InterfaceC0382w interfaceC0382w = (InterfaceC0382w) this.f13421v;
                ?? r12 = this.f13422w;
                this.f13420u = 1;
                obj = r12.k(interfaceC0382w, this);
                if (obj == aVar) {
                    return aVar;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                C1.N(obj);
            }
            return (c) obj;
        } catch (Exception e8) {
            if (e8 instanceof CancellationException) {
                throw e8;
            }
            if (!(e8 instanceof C0133q)) {
                return e8 instanceof W4.b ? new X4.a(new W4.b()) : e8 instanceof IOException ? new X4.a(new W4.c((IOException) e8)) : new X4.a(new W4.a(null, e8));
            }
            C0133q c0133q = (C0133q) e8;
            int i5 = c0133q.f2716q;
            if (i5 != 400) {
                return i5 != 401 ? i5 != 408 ? new X4.a(new W4.a(null, e8)) : new X4.a(new e((C0133q) e8)) : new X4.a(new W4.b());
            }
            T t6 = c0133q.f2717r;
            if (t6 == null || (d8 = t6.f2679c) == null) {
                strN0 = null;
            } else {
                C1731g c1731g = (C1731g) d8.f14023t;
                try {
                    s sVar = (s) d8.f14022s;
                    if (sVar != null) {
                        Charset charsetForName = X6.a.f7235a;
                        String[] strArr = sVar.f14134c;
                        int i8 = 0;
                        int iT = u0.t(0, strArr.length - 1, 2);
                        if (iT >= 0) {
                            while (!X6.n.I(strArr[i8], "charset")) {
                                if (i8 == iT) {
                                    str = null;
                                    break;
                                }
                                i8 += 2;
                            }
                            str = strArr[i8 + 1];
                            if (str != null) {
                                try {
                                    charsetForName = Charset.forName(str);
                                } catch (IllegalArgumentException unused) {
                                }
                            }
                            if (charsetForName == null) {
                                charsetForName = X6.a.f7235a;
                            }
                            strN0 = c1731g.n0(c1731g.f18765r, l7.b.s(c1731g, charsetForName));
                        } else {
                            str = null;
                            if (str != null) {
                            }
                            if (charsetForName == null) {
                            }
                            strN0 = c1731g.n0(c1731g.f18765r, l7.b.s(c1731g, charsetForName));
                        }
                    }
                } catch (Throwable th) {
                    try {
                        throw th;
                    } catch (Throwable th2) {
                        C1.g(c1731g, th);
                        throw th2;
                    }
                }
            }
            if (strN0 == null) {
                strN0 = "";
            }
            try {
                objJ = (ErrorResponse) AbstractC1033b.f13423a.a(ErrorResponse.class).a(strN0);
            } catch (Throwable th3) {
                objJ = C1.j(th3);
            }
            if (objJ instanceof A6.i) {
                objJ = null;
            }
            ErrorResponse errorResponse = (ErrorResponse) objJ;
            String str2 = errorResponse != null ? errorResponse.f10766a : null;
            return new X4.a(new W4.a(str2 != null ? str2 : "", e8));
        }
    }
}
