Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ public void downloadPackage(JSONObject updatePackage, String expectedBundleFileN
}

connection.setRequestProperty("Accept-Encoding", "identity");

int responseCode = connection.getResponseCode();
if (responseCode < 200 || responseCode >= 300) {
throw new CodePushUnknownException("Error downloading update package. Response code: "
+ responseCode + ". Response body: " + NetworkUtils.readStreamToString(connection.getErrorStream()));
}

bin = new BufferedInputStream(connection.getInputStream());

long totalBytes = connection.getContentLength();
Expand Down Expand Up @@ -349,6 +356,13 @@ public void downloadAndReplaceCurrentBundle(String remoteBundleUrl, String bundl
try {
downloadUrl = new URL(remoteBundleUrl);
connection = (HttpURLConnection) (downloadUrl.openConnection());

int responseCode = connection.getResponseCode();
if (responseCode < 200 || responseCode >= 300) {
throw new CodePushUnknownException("Error downloading update package. Response code: "
+ responseCode + ". Response body: " + NetworkUtils.readStreamToString(connection.getErrorStream()));
}

bin = new BufferedInputStream(connection.getInputStream());
File downloadFile = new File(getCurrentPackageBundlePath(bundleFileName));
downloadFile.delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@file:JvmName("NetworkUtils")

package com.microsoft.codepush.react

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.

}