From 5f59432e48802048d12af8b30fd39e5cc98f4b34 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 17 Oct 2023 10:01:58 +0300 Subject: [PATCH] Handle NPE during network requests --- .../org/koitharu/kotatsu/core/network/GZipInterceptor.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/network/GZipInterceptor.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/network/GZipInterceptor.kt index 1e53a4e7e..09a544105 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/network/GZipInterceptor.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/network/GZipInterceptor.kt @@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.network import okhttp3.Interceptor import okhttp3.Response +import okio.IOException import org.koitharu.kotatsu.core.network.CommonHeaders.CONTENT_ENCODING class GZipInterceptor : Interceptor { @@ -9,6 +10,10 @@ class GZipInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val newRequest = chain.request().newBuilder() newRequest.addHeader(CONTENT_ENCODING, "gzip") - return chain.proceed(newRequest.build()) + return try { + chain.proceed(newRequest.build()) + } catch (e: NullPointerException) { + throw IOException(e) + } } }