Skip to content

Commit 01320a6

Browse files
committed
Better error messages when retrieving betas
1 parent 1278340 commit 01320a6

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
implementation 'org.apache.commons:commons-compress:1.23.0'
5656
implementation 'info.picocli:picocli:4.7.4'
5757

58-
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
58+
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
5959
testImplementation 'org.testfx:openjfx-monocle:jdk-12.0.1+2'
6060
}
6161

src/main/java/airsquared/blobsaver/app/Network.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.BufferedReader;
2626
import java.io.IOException;
27+
import java.io.InputStream;
2728
import java.io.InputStreamReader;
2829
import java.net.HttpURLConnection;
2930
import java.net.URI;
@@ -82,8 +83,15 @@ private static HttpRequest.BodyPublisher buildFormDataFromMap(Map<Object, Object
8283
}
8384

8485
static JsonElement makeJsonRequest(String url) throws IOException {
85-
try (var inputStream = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
86-
return JsonParser.parseReader(inputStream);
86+
try {
87+
HttpResponse<InputStream> response = httpClient.send(HttpRequest.newBuilder(URI.create(url)).build(),
88+
HttpResponse.BodyHandlers.ofInputStream());
89+
if (failure(response.statusCode())) {
90+
throw new IOException("HTTP Response was " + response);
91+
}
92+
return JsonParser.parseReader(new BufferedReader(new InputStreamReader(response.body())));
93+
} catch (InterruptedException e) {
94+
throw new IOException(e);
8795
}
8896
}
8997

@@ -94,12 +102,16 @@ static void makeVoidRequest(String url) throws IOException, InterruptedException
94102
static HttpResponse<Path> downloadFile(String url, Path dir) throws IOException, InterruptedException {
95103
var response = httpClient.send(HttpRequest.newBuilder(URI.create(url)).build(),
96104
HttpResponse.BodyHandlers.ofFile(dir, WRITE, CREATE, TRUNCATE_EXISTING));
97-
if (response.statusCode() != 200) {
105+
if (failure(response.statusCode())) {
98106
throw new IOException("HTTP Response was " + response);
99107
}
100108
return response;
101109
}
102110

111+
private static boolean failure(int statusCode) {
112+
return statusCode < 200 || statusCode > 299;
113+
}
114+
103115
/**
104116
* Source: https://github.com/jcodec/jcodec/blob/6e1ec651eca92d21b41f9790143a0e6e4d26811e/android/src/main/org/jcodec/common/io/HttpChannel.java
105117
*

src/main/java/airsquared/blobsaver/app/TSS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private List<Utils.IOSVersion> getIOSVersions() throws TSSException {
302302
Stream<Utils.IOSVersion> signedBetas = getSignedBetas(deviceIdentifier);
303303
return Stream.concat(signedFirmwares, signedBetas).toList();
304304
} catch (Exception e) {
305-
throw new TSSException("There was an error retrieving beta versions; try without including beta versions.", false, e);
305+
throw new TSSException("There was an error retrieving beta versions; try without including beta versions. For more information, try again with the debug log open.", false, e);
306306
}
307307
} else { // all signed firmwares
308308
return getSignedFirmwares(deviceIdentifier).toList();

0 commit comments

Comments
 (0)