Skip to content

Android: more meaningful errors for non-200 HTTP responses - #52

Merged
ofalvai merged 1 commit into
masterfrom
push-mlopoykmnlnr
Sep 3, 2026
Merged

Android: more meaningful errors for non-200 HTTP responses#52
ofalvai merged 1 commit into
masterfrom
push-mlopoykmnlnr

Conversation

@ofalvai

@ofalvai ofalvai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Why

This isn't very useful:

09-02 02:40:24.945  5764  5834 E ReactNative: [CodePush] Exception
09-02 02:40:24.945  5764  5834 E ReactNative: java.io.FileNotFoundException: https://storage-gateway.services.bitrise.io/code-push-artifacts-storage-prod-4afa6c4aa8991295/apps/fd0696cb-cbbc-40ee-ac9c-5cde1208f632/deployments/759fe29b-8f1c-40bc-96da-de0bc32a2fd0/packages/a00041bf-6fea-1a4c-5b63-fc5643a434c6/update.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ZACHYSDP4V1H5JC91OW7%2F20260902%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260902T024021Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=7f95d164cdfe840db860bd7f08fac0fcbf7d7795e04d7e9452c30c91338edfb0
	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:255)
	at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211)
	at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30)
	at com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage(CodePushUpdateManager.java:181)
	at com.microsoft.codepush.react.CodePushNativeModule$2.doInBackground(CodePushNativeModule.java:351)
	at com.microsoft.codepush.react.CodePushNativeModule$2.doInBackground(CodePushNativeModule.java:345)
	at android.os.AsyncTask$3.call(AsyncTask.java:394)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
	at java.lang.Thread.run(Thread.java:1012)

...although that FileNotFoundException is thrown in case of a 404 response.

What

Log the HTTP response code and response body.

Note about iOS: it doesn't suffer from the same issue, and HTTP errors bubble up to the JS side, where they are logged. So I wouldn't touch the iOS side now.

import java.io.InputStream

fun readStreamToString(inputStream: InputStream?): String {
return inputStream?.bufferedReader()?.use { it.readText() } ?: ""

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create a separate file for this one-liner? This comes from the Kotlin stdlib, so we can't do this same trick in CodePushUpdateManager.java. And because Android Java is stuck on Java 8 APIs, we would need to reimplement this in ~50 lines of Java.

@ofalvai
ofalvai merged commit b144438 into master Sep 3, 2026
6 checks passed
@ofalvai
ofalvai deleted the push-mlopoykmnlnr branch September 3, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants