From 75461c1330da99411bfe34b973165ab4f5676e99 Mon Sep 17 00:00:00 2001 From: Niklas Berglund Date: Tue, 20 Aug 2024 10:39:13 +0200 Subject: [PATCH] Log response status code on error --- .../test/e2e/misc/SimpleMullvadHttpClient.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt index a72f27a3efa6..734f26653749 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.test.services.events.TestEventException import co.touchlab.kermit.Logger import com.android.volley.Request +import com.android.volley.VolleyError import com.android.volley.toolbox.JsonArrayRequest import com.android.volley.toolbox.JsonObjectRequest import com.android.volley.toolbox.RequestFuture @@ -106,8 +107,9 @@ class SimpleMullvadHttpClient(context: Context) { authorizationHeader: String? = null ): JSONObject? { val future = RequestFuture.newFuture() + val request = - object : JsonObjectRequest(method, url, body, future, future) { + object : JsonObjectRequest(method, url, body, future, onErrorResponse) { override fun getHeaders(): MutableMap { val headers = HashMap() if (body != null) { @@ -136,7 +138,7 @@ class SimpleMullvadHttpClient(context: Context) { ): String? { val future = RequestFuture.newFuture() val request = - object : StringRequest(method, url, future, future) { + object : StringRequest(method, url, future, onErrorResponse) { override fun getHeaders(): MutableMap { val headers = HashMap() if (body != null) { @@ -165,7 +167,7 @@ class SimpleMullvadHttpClient(context: Context) { ): JSONArray? { val future = RequestFuture.newFuture() val request = - object : JsonArrayRequest(method, url, null, future, future) { + object : JsonArrayRequest(method, url, null, future, onErrorResponse) { override fun getHeaders(): MutableMap { val headers = HashMap() headers.put("Content-Type", "application/json") @@ -190,5 +192,9 @@ class SimpleMullvadHttpClient(context: Context) { companion object { private const val REQUEST_ERROR_MESSAGE = "Unable to verify account due to invalid account or connectivity issues." + + private val onErrorResponse = { error: VolleyError -> + Logger.e("Response returned error status code: ${error.networkResponse.statusCode}") + } } }