Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f6005e5

Browse files
authoredApr 15, 2025··
Merge pull request #418 from IABTechLab/sch-UID2-4661-log-http-errors-to-core
sch-UID2-4661 detailed error message when http request to core is not a success
2 parents 10de7c8 + 3635fad commit f6005e5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
 

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private InputStream readContentFromLocalFileSystem(String path, Proxy proxy) thr
9797
return (proxy == null ? new URL(path).openConnection() : new URL(path).openConnection(proxy)).getInputStream();
9898
}
9999

100-
private InputStream getWithAttest(String path) throws IOException, AttestationResponseHandlerException {
100+
private InputStream getWithAttest(String path) throws IOException, AttestationResponseHandlerException, CloudStorageException {
101101
if (!attestationResponseHandler.attested()) {
102102
attestationResponseHandler.attest();
103103
}
@@ -106,7 +106,9 @@ private InputStream getWithAttest(String path) throws IOException, AttestationRe
106106

107107
HttpResponse<String> httpResponse;
108108
httpResponse = sendHttpRequest(path, attestationToken);
109-
109+
if (httpResponse.statusCode() != 200) {
110+
throw new CloudStorageException(String.format("Non-success response from core on request to %s. Status code: %d. Response: %s", path, httpResponse.statusCode(), httpResponse.body()));
111+
}
110112
return Utils.convertHttpResponseToInputStream(httpResponse);
111113
}
112114

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void Download_Succeed_RequestSentWithExpectedParameters() throws IOExcept
4747

4848
String expectedResponseBody = "Hello, world!";
4949
when(mockHttpResponse.body()).thenReturn(expectedResponseBody);
50+
when(mockHttpResponse.statusCode()).thenReturn(200);
5051

5152
HashMap<String, String> expectedHeaders = new HashMap<>();
5253
expectedHeaders.put(Const.Http.AppVersionHeader, "testAppVersionHeader");
@@ -73,7 +74,7 @@ public void Download_AttestInternalFail_ExceptionThrown() throws IOException, At
7374
}
7475

7576
@Test
76-
public void Download_Attest401_getOptOut_NotCalled() throws CloudStorageException, IOException, AttestationResponseHandlerException {
77+
public void Download_Attest401_getOptOut_NotCalled() throws IOException, AttestationResponseHandlerException {
7778
HttpResponse<String> mockHttpResponse = mock(HttpResponse.class);
7879
when(mockHttpResponse.statusCode()).thenReturn(401);
7980

@@ -82,7 +83,10 @@ public void Download_Attest401_getOptOut_NotCalled() throws CloudStorageExceptio
8283

8384
when(mockHttpClient.get(eq("https://download"), any(HashMap.class))).thenReturn(mockHttpResponse);
8485

85-
uidCoreClient.download("https://download");
86+
assertThrows(CloudStorageException.class, () -> {
87+
uidCoreClient.download("https://download");
88+
});
89+
8690
verify(mockAttestationResponseHandler, times(1)).attest();
8791
verify(mockAttestationResponseHandler, never()).getOptOutUrl();
8892
}

0 commit comments

Comments
 (0)
Please sign in to comment.