Skip to content

Commit ae8e02d

Browse files
authored
Merge pull request #570 from IABTechLab/wzh-UID2-5185-add-more-failure-logging
Wzh UI d2 5185 add more failure logging
2 parents 20bc153 + 6a11d6d commit ae8e02d

File tree

4 files changed

+109
-9
lines changed

4 files changed

+109
-9
lines changed

src/main/java/com/uid2/shared/attest/UidCoreClient.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ private InputStream internalDownload(String path) throws CloudStorageException {
8989
inputStream = getWithAttest(path);
9090
}
9191
return inputStream;
92+
} catch (CloudStorageException e) {
93+
throw e;
9294
} catch (Exception e) {
93-
throw new CloudStorageException("download error: " + e.getMessage(), e);
95+
throw new CloudStorageException(
96+
"E12: Data Download Failure - exception: " + e.getClass().getSimpleName() +
97+
". For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator.", e);
9498
}
9599
}
96100

@@ -108,7 +112,9 @@ private InputStream getWithAttest(String path) throws IOException, AttestationRe
108112
HttpResponse<String> httpResponse;
109113
httpResponse = sendHttpRequest(path, attestationToken);
110114
if (httpResponse.statusCode() != 200) {
111-
throw new CloudStorageException(String.format("Non-success response from core on request to %s. Status code: %d", path, httpResponse.statusCode()));
115+
throw new CloudStorageException(String.format(
116+
"E12: Data Download Failure - HTTP response code %d. For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator.",
117+
httpResponse.statusCode()));
112118
}
113119
return Utils.convertHttpResponseToInputStream(httpResponse);
114120
}

src/main/java/com/uid2/shared/cloud/URLStorageWithMetadata.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public InputStream download(String cloudPath) throws CloudStorageException {
4848
if (responseCode >= 200 && responseCode < 300) {
4949
return httpConn.getInputStream();
5050
} else {
51-
throw new CloudStorageException("Cannot download required files, HTTP response code " + responseCode
52-
+ ", please visit UID2 guides for more details");
51+
throw new CloudStorageException("E12: Data Download Failure - HTTP response code " + responseCode
52+
+ ". For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator.");
5353
}
5454
}
5555
catch (CloudStorageException e) {
@@ -58,8 +58,8 @@ public InputStream download(String cloudPath) throws CloudStorageException {
5858
}
5959
catch (Throwable t) {
6060
// Do not log the original exception as it may contain sensitive information such as the pre-signed URL
61-
throw new CloudStorageException("Cannot download required files, exception: " + t.getClass().getSimpleName() +
62-
", please visit UID2 guides for more details");
61+
throw new CloudStorageException("E12: Data Download Failure - exception: " + t.getClass().getSimpleName() +
62+
". For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator.");
6363
}
6464
}
6565

src/main/java/com/uid2/shared/vertx/CloudSyncVerticle.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,13 @@ private void cloudDownloadBlocking(String s3Path) throws Exception {
400400

401401
downloadFailureTimer.record(java.time.Duration.ofMillis(cloudDownloadTimeMs));
402402
// Be careful as the s3Path may contain the pre-signed S3 token, so do not log the whole path
403-
LOGGER.error("download error: " + ex.getClass().getSimpleName());
404-
throw new CloudStorageException("Download failed");
403+
LOGGER.error("Cloud storage download error, exception type: " + ex.getClass().getSimpleName());
404+
405+
if (ex instanceof CloudStorageException) {
406+
throw (CloudStorageException) ex;
407+
}
408+
throw new CloudStorageException("E12: Data Download Failure - Failed to download file from cloud storage, exception: "
409+
+ ex.getClass().getSimpleName() + ". Check network connectivity and service availability.");
405410
}
406411
}
407412

src/test/java/com/uid2/shared/attest/UidCoreClientTest.java

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void Download_AttestInternalFail_ExceptionThrown() throws IOException, At
7272
CloudStorageException result = assertThrows(CloudStorageException.class, () -> {
7373
uidCoreClient.download("https://download");
7474
});
75-
String expectedExceptionMessage = "download error: AttestationResponseCode: AttestationFailure, test failure";
75+
String expectedExceptionMessage = "E12: Data Download Failure - exception: AttestationResponseHandlerException. For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator.";
7676
assertEquals(expectedExceptionMessage, result.getMessage());
7777
}
7878

@@ -100,4 +100,93 @@ void getJwtReturnsCoreToken() {
100100
when(mockAttestationResponseHandler.getCoreJWT()).thenReturn("coreJWT");
101101
Assertions.assertEquals("coreJWT", this.uidCoreClient.getJWT());
102102
}
103+
104+
@Test
105+
public void Download_Http403Error_LogsStatusCodeAndEndpoint() throws IOException, AttestationResponseHandlerException {
106+
HttpResponse<String> mockHttpResponse = mock(HttpResponse.class);
107+
when(mockHttpResponse.statusCode()).thenReturn(403);
108+
when(mockHttpClient.get(eq("https://core-prod.uidapi.com/sites/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse);
109+
110+
CloudStorageException result = assertThrows(CloudStorageException.class, () -> {
111+
uidCoreClient.download("https://core-prod.uidapi.com/sites/refresh");
112+
});
113+
114+
assertAll(
115+
() -> assertTrue(result.getMessage().contains("E12: Data Download Failure"),
116+
"Expected E12 error code in message"),
117+
() -> assertTrue(result.getMessage().contains("HTTP response code 403"),
118+
"Expected HTTP status code 403 in message"),
119+
() -> assertTrue(result.getMessage().contains("For troubleshooting information, refer to the applicable Private Operator guide"),
120+
"Expected documentation reference in message")
121+
);
122+
}
123+
124+
@Test
125+
public void Download_Http404Error_LogsStatusCode() throws IOException, AttestationResponseHandlerException {
126+
HttpResponse<String> mockHttpResponse = mock(HttpResponse.class);
127+
when(mockHttpResponse.statusCode()).thenReturn(404);
128+
when(mockHttpClient.get(eq("https://core-prod.uidapi.com/keys/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse);
129+
130+
CloudStorageException result = assertThrows(CloudStorageException.class, () -> {
131+
uidCoreClient.download("https://core-prod.uidapi.com/keys/refresh");
132+
});
133+
134+
assertAll(
135+
() -> assertTrue(result.getMessage().contains("HTTP response code 404"),
136+
"Expected HTTP status code 404 in message"),
137+
() -> assertTrue(result.getMessage().contains("E12: Data Download Failure"),
138+
"Expected E12 error code in message")
139+
);
140+
}
141+
142+
@Test
143+
public void Download_Http500Error_LogsStatusCode() throws IOException, AttestationResponseHandlerException {
144+
HttpResponse<String> mockHttpResponse = mock(HttpResponse.class);
145+
when(mockHttpResponse.statusCode()).thenReturn(500);
146+
when(mockHttpClient.get(eq("https://core-prod.uidapi.com/salts/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse);
147+
148+
CloudStorageException result = assertThrows(CloudStorageException.class, () -> {
149+
uidCoreClient.download("https://core-prod.uidapi.com/salts/refresh");
150+
});
151+
152+
assertAll(
153+
() -> assertTrue(result.getMessage().contains("E12: Data Download Failure"),
154+
"Expected E12 error code in message"),
155+
() -> assertTrue(result.getMessage().contains("HTTP response code 500"),
156+
"Expected HTTP status code 500 in message")
157+
);
158+
}
159+
160+
@Test
161+
public void Download_Http503Error_LogsStatusCode() throws IOException, AttestationResponseHandlerException {
162+
HttpResponse<String> mockHttpResponse = mock(HttpResponse.class);
163+
when(mockHttpResponse.statusCode()).thenReturn(503);
164+
when(mockHttpClient.get(eq("https://core-integ.uidapi.com/clients/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse);
165+
166+
CloudStorageException result = assertThrows(CloudStorageException.class, () -> {
167+
uidCoreClient.download("https://core-integ.uidapi.com/clients/refresh");
168+
});
169+
170+
assertTrue(result.getMessage().contains("HTTP response code 503"),
171+
"Expected HTTP status code 503 in message");
172+
}
173+
174+
@Test
175+
public void Download_NetworkError_LogsExceptionType() throws IOException, AttestationResponseHandlerException {
176+
IOException networkException = new IOException("Connection timeout");
177+
when(mockHttpClient.get(anyString(), any(HashMap.class))).thenThrow(networkException);
178+
179+
CloudStorageException result = assertThrows(CloudStorageException.class, () -> {
180+
uidCoreClient.download("https://core-prod.uidapi.com/sites/refresh");
181+
});
182+
183+
assertAll(
184+
() -> assertTrue(result.getMessage().contains("E12: Data Download Failure"),
185+
"Expected E12 error code in message"),
186+
() -> assertTrue(result.getMessage().contains("exception: IOException"),
187+
"Expected exception type in message"),
188+
() -> assertTrue(result.getMessage().contains("For troubleshooting information, refer to the applicable Private Operator guide"),
189+
"Expected documentation reference in message")
190+
);
191+
}
103192
}

0 commit comments

Comments
 (0)