Skip to content

Commit 427136d

Browse files
fix: Fix managing network errors (box/box-codegen#798) (#1377)
1 parent 4c718e2 commit 427136d

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "02b749b", "specHash": "623b811", "version": "0.1.0" }
1+
{ "engineHash": "d090a8d", "specHash": "623b811", "version": "0.1.0" }

src/main/java/com/box/sdkgen/box/errors/BoxSDKError.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ public class BoxSDKError extends RuntimeException {
1111
public String name;
1212

1313
public BoxSDKError(String message) {
14+
super(message);
1415
this.message = message;
1516
this.name = "BoxSDKError";
1617
}
1718

1819
public BoxSDKError(String message, Exception error) {
20+
super(message, error);
1921
this.message = message;
2022
this.error = error;
2123
this.name = "BoxSDKError";
2224
}
2325

2426
protected BoxSDKError(Builder builder) {
27+
super(builder.message, builder.error);
2528
this.message = builder.message;
2629
this.timestamp = builder.timestamp;
2730
this.error = builder.error;

src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public FetchResponse fetch(FetchOptions options) {
7777

7878
boolean authenticationNeeded = false;
7979
Request request;
80-
FetchResponse fetchResponse = null;
80+
FetchResponse fetchResponse = new FetchResponse.Builder(0, new TreeMap<>()).build();
8181
Exception exceptionThrown = null;
8282

8383
int attemptNumber = 1;
@@ -140,9 +140,6 @@ public FetchResponse fetch(FetchOptions options) {
140140
if (response != null) {
141141
response.close();
142142
}
143-
144-
fetchResponse =
145-
new FetchResponse.Builder(0, new TreeMap<>(String.CASE_INSENSITIVE_ORDER)).build();
146143
}
147144

148145
shouldRetry =
@@ -167,8 +164,7 @@ public FetchResponse fetch(FetchOptions options) {
167164
continue;
168165
}
169166

170-
if (fetchResponse != null
171-
&& fetchResponse.getStatus() >= 300
167+
if (fetchResponse.getStatus() >= 300
172168
&& fetchResponse.getStatus() < 400
173169
&& fetchOptions.followRedirects) {
174170
if (!fetchResponse.getHeaders().containsKey("Location")) {
@@ -189,9 +185,7 @@ public FetchResponse fetch(FetchOptions options) {
189185
.build());
190186
}
191187

192-
if (fetchResponse != null
193-
&& fetchResponse.getStatus() >= 200
194-
&& fetchResponse.getStatus() < 400) {
188+
if (fetchResponse.getStatus() >= 200 && fetchResponse.getStatus() < 400) {
195189
return fetchResponse;
196190
}
197191

@@ -313,7 +307,7 @@ private static void throwOnUnsuccessfulResponse(
313307
String rawResponseBody,
314308
Exception exceptionThrown,
315309
DataSanitizer dataSanitizer) {
316-
if (fetchResponse == null) {
310+
if (fetchResponse.getStatus() == 0 && exceptionThrown != null) {
317311
throw new BoxSDKError(exceptionThrown.getMessage(), exceptionThrown);
318312
}
319313
try {

src/main/java/com/box/sdkgen/serialization/json/JsonManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static String sanitizedValue() {
9393
}
9494

9595
public static JsonNode sanitizeSerializedData(JsonNode sd, Map<String, String> keysToSanitize) {
96-
if (!sd.isObject()) {
96+
if (sd == null || !sd.isObject()) {
9797
return sd;
9898
}
9999
Map<String, JsonNode> sanitizedDictionary = new HashMap<>();

0 commit comments

Comments
 (0)