ChatOn v1.35.366360版本的 MD5 值为:cde28447b38d5467efa95e48e7076155

以下内容为反编译后的 ApiErrorMapper.java 源代码,内容仅作参考


package com.qonversion.android.sdk.internal.api;

import com.itextpdf.text.pdf.PdfObject;
import com.itextpdf.text.pdf.codec.JBIG2SegmentReader;
import com.itextpdf.text.xml.xmp.XmpWriter;
import com.qonversion.android.sdk.dto.QonversionError;
import com.qonversion.android.sdk.dto.QonversionErrorCode;
import il.g;
import il.i;
import java.io.IOException;
import java.nio.charset.Charset;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
import retrofit2.Response;
import vk.h0;
import vk.r0;
@Metadata(d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0000\u0018\u0000 \u001e2\u00020\u0001:\u0001\u001eB\u0011\b\u0007\u0012\u0006\u0010\u001a\u001a\u00020\u0019¢\u0006\u0004\b\u001c\u0010\u001dJ\u0010\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\u0016\u0010\b\u001a\u0004\u0018\u00010\u0006*\u00020\u00062\u0006\u0010\u0007\u001a\u00020\u0004H\u0002J\u001f\u0010\n\u001a\u0004\u0018\u00010\t*\u0004\u0018\u00010\u00062\u0006\u0010\u0007\u001a\u00020\u0004H\u0002¢\u0006\u0004\b\n\u0010\u000bJ\u0018\u0010\f\u001a\u0004\u0018\u00010\u0004*\u0004\u0018\u00010\u00062\u0006\u0010\u0007\u001a\u00020\u0004H\u0002J\u0018\u0010\u000e\u001a\u0004\u0018\u00010\u0004*\u0004\u0018\u00010\u00012\u0006\u0010\r\u001a\u00020\u0004H\u0002J\u0019\u0010\u0011\u001a\u00020\u00102\b\u0010\u000f\u001a\u0004\u0018\u00010\tH\u0002¢\u0006\u0004\b\u0011\u0010\u0012J\u001b\u0010\u0013\u001a\u0004\u0018\u00010\u00042\b\u0010\u000f\u001a\u0004\u0018\u00010\tH\u0002¢\u0006\u0004\b\u0013\u0010\u0014J\u001a\u0010\u0018\u001a\u00020\u0017\"\u0004\b\u0000\u0010\u00152\f\u0010\u000f\u001a\b\u0012\u0004\u0012\u00028\u00000\u0016R\u0014\u0010\u001a\u001a\u00020\u00198\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001a\u0010\u001b¨\u0006\u001f"}, d2 = {"Lcom/qonversion/android/sdk/internal/api/ApiErrorMapper;", PdfObject.NOTHING, "Lvk/r0;", "response", PdfObject.NOTHING, "convertResponseBody", "Lorg/json/JSONObject;", "field", "getJsonObject", PdfObject.NOTHING, "getInt", "(Lorg/json/JSONObject;Ljava/lang/String;)Ljava/lang/Integer;", "getString", "fieldName", "toFormatString", "value", "Lcom/qonversion/android/sdk/dto/QonversionErrorCode;", "getQonversionErrorCode", "(Ljava/lang/Integer;)Lcom/qonversion/android/sdk/dto/QonversionErrorCode;", "getAdditionalMessageForCode", "(Ljava/lang/Integer;)Ljava/lang/String;", "T", "Lretrofit2/Response;", "Lcom/qonversion/android/sdk/dto/QonversionError;", "getErrorFromResponse", "Lcom/qonversion/android/sdk/internal/api/ApiHelper;", "helper", "Lcom/qonversion/android/sdk/internal/api/ApiHelper;", "<init>", "(Lcom/qonversion/android/sdk/internal/api/ApiHelper;)V", "Companion", "sdk_release"}, k = 1, mv = {1, 6, 0})
public final class ApiErrorMapper {
    @NotNull
    private static final String CODE = "code";
    @NotNull
    public static final Companion Companion = new Companion(null);
    @NotNull
    private static final String DATA = "data";
    @NotNull
    private static final String ERROR = "error";
    @NotNull
    private static final String MESSAGE = "message";
    @NotNull
    private final ApiHelper helper;

    @Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0004\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000¨\u0006\b"}, d2 = {"Lcom/qonversion/android/sdk/internal/api/ApiErrorMapper$Companion;", PdfObject.NOTHING, "()V", "CODE", PdfObject.NOTHING, "DATA", "ERROR", "MESSAGE", "sdk_release"}, k = 1, mv = {1, 6, 0}, xi = JBIG2SegmentReader.PAGE_INFORMATION)
    public static final class Companion {
        private Companion() {
        }

        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }
    }

    public ApiErrorMapper(@NotNull ApiHelper helper) {
        Intrinsics.checkNotNullParameter(helper, "helper");
        this.helper = helper;
    }

    private final String convertResponseBody(r0 r0Var) {
        i source = r0Var.source();
        source.r(Long.MAX_VALUE);
        g clone = source.c().clone();
        Charset forName = Charset.forName(XmpWriter.UTF8);
        Intrinsics.checkNotNullExpressionValue(forName, "forName(\"UTF-8\")");
        return clone.a0(forName);
    }

    private final String getAdditionalMessageForCode(Integer num) {
        if (num != null && num.intValue() == 20201) {
            return "For more details please check our guide [Troubleshooting](https://documentation.qonversion.io/docs/troubleshooting)";
        }
        if (num != null && num.intValue() == 20203) {
            return "Possible reasons for this error are fraud purchases and incorrect configuration of the project key in the Qonversion Dashboard";
        }
        return null;
    }

    private final Integer getInt(JSONObject jSONObject, String str) {
        if (jSONObject == null || jSONObject.isNull(str)) {
            return null;
        }
        return Integer.valueOf(jSONObject.getInt(str));
    }

    private final JSONObject getJsonObject(JSONObject jSONObject, String str) {
        if (jSONObject.isNull(str)) {
            return null;
        }
        return jSONObject.getJSONObject(str);
    }

    private final QonversionErrorCode getQonversionErrorCode(Integer num) {
        return ((num != null && num.intValue() == 10002) || (num != null && num.intValue() == 10003)) ? QonversionErrorCode.InvalidCredentials : ((num != null && num.intValue() == 10004) || (num != null && num.intValue() == 10005) || (num != null && num.intValue() == 20014)) ? QonversionErrorCode.InvalidClientUid : (num != null && num.intValue() == 10006) ? QonversionErrorCode.UnknownClientPlatform : (num != null && num.intValue() == 10008) ? QonversionErrorCode.FraudPurchase : (num != null && num.intValue() == 20005) ? QonversionErrorCode.FeatureNotSupported : ((num != null && num.intValue() == 20006) || (num != null && num.intValue() == 20007) || ((num != null && num.intValue() == 20300) || ((num != null && num.intValue() == 20303) || (num != null && num.intValue() == 20399)))) ? QonversionErrorCode.PlayStoreError : ((num != null && num.intValue() == 20008) || (num != null && num.intValue() == 20010) || ((num != null && num.intValue() == 20203) || (num != null && num.intValue() == 20210))) ? QonversionErrorCode.PurchaseInvalid : ((num != null && num.intValue() == 20011) || (num != null && num.intValue() == 20012) || (num != null && num.intValue() == 20013)) ? QonversionErrorCode.ProjectConfigError : (num != null && num.intValue() == 20201) ? QonversionErrorCode.InvalidStoreCredentials : QonversionErrorCode.BackendError;
    }

    private final String getString(JSONObject jSONObject, String str) {
        if (jSONObject == null || jSONObject.isNull(str)) {
            return null;
        }
        return jSONObject.getString(str);
    }

    private final String toFormatString(Object obj, String str) {
        if (obj == null) {
            return null;
        }
        return str + '=' + obj;
    }

    @NotNull
    public final <T> QonversionError getErrorFromResponse(@NotNull Response<T> value) {
        String str;
        JSONObject jSONObject;
        h0 request;
        ApiHelper apiHelper;
        Intrinsics.checkNotNullParameter(value, "value");
        String str2 = new String();
        r0 errorBody = value.errorBody();
        Integer num = null;
        if (errorBody != null) {
            try {
                jSONObject = new JSONObject(convertResponseBody(errorBody));
                request = value.raw().f20519d;
                apiHelper = this.helper;
                Intrinsics.checkNotNullExpressionValue(request, "request");
            } catch (IOException e10) {
                str = "error=" + e10.getLocalizedMessage();
                Unit unit = Unit.f14034a;
            } catch (JSONException unused) {
                Unit unit2 = Unit.f14034a;
                str = "error=failed to parse the backend response";
            }
            if (apiHelper.isV1Request(request)) {
                JSONObject jsonObject = getJsonObject(jSONObject, DATA);
                String formatString = toFormatString(jsonObject, DATA);
                if (formatString != null) {
                    str2 = formatString;
                }
                num = getInt(jsonObject, CODE);
                Unit unit3 = Unit.f14034a;
            } else {
                str = toFormatString(getString(getJsonObject(jSONObject, ERROR), MESSAGE), ERROR);
                if (str != null) {
                    Unit unit4 = Unit.f14034a;
                    str2 = str;
                }
            }
        }
        QonversionErrorCode qonversionErrorCode = getQonversionErrorCode(num);
        String additionalMessageForCode = getAdditionalMessageForCode(num);
        StringBuilder sb2 = new StringBuilder("HTTP status code=");
        sb2.append(value.code());
        sb2.append(", ");
        sb2.append(str2);
        sb2.append(". ");
        if (additionalMessageForCode == null) {
            additionalMessageForCode = PdfObject.NOTHING;
        }
        sb2.append(additionalMessageForCode);
        return new QonversionError(qonversionErrorCode, sb2.toString());
    }
}