-
Notifications
You must be signed in to change notification settings - Fork 9
Wzh UI d2 5185 add more failure logging #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b57e1ba
3679295
b9667b5
c0c2248
cd728cf
e292810
862e52c
2cf3ce0
21ccfd3
0730b22
43eb869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,8 +89,12 @@ private InputStream internalDownload(String path) throws CloudStorageException { | |
| inputStream = getWithAttest(path); | ||
| } | ||
| return inputStream; | ||
| } catch (CloudStorageException e) { | ||
| throw e; | ||
| } catch (Exception e) { | ||
| throw new CloudStorageException("download error: " + e.getMessage(), e); | ||
| throw new CloudStorageException( | ||
| "E12: Data Download Failure - exception: " + e.getClass().getSimpleName() + | ||
| ". Please visit UID2 guides for troubleshooting", e); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -108,7 +112,9 @@ private InputStream getWithAttest(String path) throws IOException, AttestationRe | |
| HttpResponse<String> httpResponse; | ||
| httpResponse = sendHttpRequest(path, attestationToken); | ||
| if (httpResponse.statusCode() != 200) { | ||
| throw new CloudStorageException(String.format("Non-success response from core on request to %s. Status code: %d", path, httpResponse.statusCode())); | ||
| throw new CloudStorageException(String.format( | ||
| "E12: Data Download Failure - HTTP response code %d. Please visit UID2 guides for troubleshooting", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly the same -- We don't generally say "please" in documentation. People visit a site or a page but not a guide. Also, is it possible to include a link? If not a specific guide, you could link to the Private Operator overview page: https://unifiedid.com/docs/guides/integration-options-private-operator. Just a suggestion. Suggestion for copy: "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.", |
||
| httpResponse.statusCode())); | ||
| } | ||
| return Utils.convertHttpResponseToInputStream(httpResponse); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,8 @@ public InputStream download(String cloudPath) throws CloudStorageException { | |
| if (responseCode >= 200 && responseCode < 300) { | ||
| return httpConn.getInputStream(); | ||
| } else { | ||
| throw new CloudStorageException("Cannot download required files, HTTP response code " + responseCode | ||
| + ", please visit UID2 guides for more details"); | ||
| throw new CloudStorageException("E12: Data Download Failure - HTTP response code " + responseCode | ||
| + ". Please visit UID2 guides for troubleshooting"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly the same -- We don't generally say "please" in documentation. People visit a site or a page but not a guide. Also, is it possible to include a link? If not a specific guide, you could link to the Private Operator overview page: https://unifiedid.com/docs/guides/integration-options-private-operator. Just a suggestion. Suggestion for copy: ". For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator."); |
||
| } | ||
| } | ||
| catch (CloudStorageException e) { | ||
|
|
@@ -58,8 +58,8 @@ public InputStream download(String cloudPath) throws CloudStorageException { | |
| } | ||
| catch (Throwable t) { | ||
| // Do not log the original exception as it may contain sensitive information such as the pre-signed URL | ||
| throw new CloudStorageException("Cannot download required files, exception: " + t.getClass().getSimpleName() + | ||
| ", please visit UID2 guides for more details"); | ||
| throw new CloudStorageException("E12: Data Download Failure - exception: " + t.getClass().getSimpleName() + | ||
| ". Please visit UID2 guides for troubleshooting"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -400,8 +400,13 @@ private void cloudDownloadBlocking(String s3Path) throws Exception { | |
|
|
||
| downloadFailureTimer.record(java.time.Duration.ofMillis(cloudDownloadTimeMs)); | ||
| // Be careful as the s3Path may contain the pre-signed S3 token, so do not log the whole path | ||
| LOGGER.error("download error: " + ex.getClass().getSimpleName()); | ||
| throw new CloudStorageException("Download failed"); | ||
| LOGGER.error("Cloud storage download error, exception type: " + ex.getClass().getSimpleName()); | ||
|
|
||
| if (ex instanceof CloudStorageException) { | ||
| throw (CloudStorageException) ex; | ||
| } | ||
| throw new CloudStorageException("Failed to download file from cloud storage, exception: " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add E12? |
||
| + ex.getClass().getSimpleName() + ", please check network connectivity and service availability"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like two sentences run into one. Plus there is no ending punctuation. Suggest ", please check network connectivity and service availability"); to: ". Check network connectivity and service availability."); |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ public void Download_AttestInternalFail_ExceptionThrown() throws IOException, At | |
| CloudStorageException result = assertThrows(CloudStorageException.class, () -> { | ||
| uidCoreClient.download("https://download"); | ||
| }); | ||
| String expectedExceptionMessage = "download error: AttestationResponseCode: AttestationFailure, test failure"; | ||
| String expectedExceptionMessage = "E12: Data Download Failure - exception: AttestationResponseHandlerException. Please visit UID2 guides for troubleshooting"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as earlier re "please" and guide wording. |
||
| assertEquals(expectedExceptionMessage, result.getMessage()); | ||
| } | ||
|
|
||
|
|
@@ -100,4 +100,93 @@ void getJwtReturnsCoreToken() { | |
| when(mockAttestationResponseHandler.getCoreJWT()).thenReturn("coreJWT"); | ||
| Assertions.assertEquals("coreJWT", this.uidCoreClient.getJWT()); | ||
| } | ||
|
|
||
| @Test | ||
| public void Download_Http403Error_LogsStatusCodeAndEndpoint() throws IOException, AttestationResponseHandlerException { | ||
| HttpResponse<String> mockHttpResponse = mock(HttpResponse.class); | ||
| when(mockHttpResponse.statusCode()).thenReturn(403); | ||
| when(mockHttpClient.get(eq("https://core-prod.uidapi.com/sites/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse); | ||
|
|
||
| CloudStorageException result = assertThrows(CloudStorageException.class, () -> { | ||
| uidCoreClient.download("https://core-prod.uidapi.com/sites/refresh"); | ||
| }); | ||
|
|
||
| assertAll( | ||
| () -> assertTrue(result.getMessage().contains("E12: Data Download Failure"), | ||
| "Should contain E12 error code"), | ||
| () -> assertTrue(result.getMessage().contains("HTTP response code 403"), | ||
| "Should contain HTTP status code 403"), | ||
| () -> assertTrue(result.getMessage().contains("Please visit UID2 guides for troubleshooting"), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as earlier... please fix all instances and I won't mark any more :-) |
||
| "Should reference documentation") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void Download_Http404Error_LogsStatusCode() throws IOException, AttestationResponseHandlerException { | ||
| HttpResponse<String> mockHttpResponse = mock(HttpResponse.class); | ||
| when(mockHttpResponse.statusCode()).thenReturn(404); | ||
| when(mockHttpClient.get(eq("https://core-prod.uidapi.com/keys/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse); | ||
|
|
||
| CloudStorageException result = assertThrows(CloudStorageException.class, () -> { | ||
| uidCoreClient.download("https://core-prod.uidapi.com/keys/refresh"); | ||
| }); | ||
|
|
||
| assertAll( | ||
| () -> assertTrue(result.getMessage().contains("HTTP response code 404"), | ||
| "Should contain HTTP status code 404"), | ||
| () -> assertTrue(result.getMessage().contains("E12: Data Download Failure"), | ||
| "Should contain E12 error code") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void Download_Http500Error_LogsStatusCode() throws IOException, AttestationResponseHandlerException { | ||
| HttpResponse<String> mockHttpResponse = mock(HttpResponse.class); | ||
| when(mockHttpResponse.statusCode()).thenReturn(500); | ||
| when(mockHttpClient.get(eq("https://core-prod.uidapi.com/salts/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse); | ||
|
|
||
| CloudStorageException result = assertThrows(CloudStorageException.class, () -> { | ||
| uidCoreClient.download("https://core-prod.uidapi.com/salts/refresh"); | ||
| }); | ||
|
|
||
| assertAll( | ||
| () -> assertTrue(result.getMessage().contains("E12: Data Download Failure"), | ||
| "Should contain E12 error code"), | ||
| () -> assertTrue(result.getMessage().contains("HTTP response code 500"), | ||
| "Should contain HTTP status code 500") | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void Download_Http503Error_LogsStatusCode() throws IOException, AttestationResponseHandlerException { | ||
| HttpResponse<String> mockHttpResponse = mock(HttpResponse.class); | ||
| when(mockHttpResponse.statusCode()).thenReturn(503); | ||
| when(mockHttpClient.get(eq("https://core-integ.uidapi.com/clients/refresh"), any(HashMap.class))).thenReturn(mockHttpResponse); | ||
|
|
||
| CloudStorageException result = assertThrows(CloudStorageException.class, () -> { | ||
| uidCoreClient.download("https://core-integ.uidapi.com/clients/refresh"); | ||
| }); | ||
|
|
||
| assertTrue(result.getMessage().contains("HTTP response code 503"), | ||
| "Should contain HTTP status code 503"); | ||
| } | ||
|
|
||
| @Test | ||
| public void Download_NetworkError_LogsExceptionType() throws IOException, AttestationResponseHandlerException { | ||
| IOException networkException = new IOException("Connection timeout"); | ||
| when(mockHttpClient.get(anyString(), any(HashMap.class))).thenThrow(networkException); | ||
|
|
||
| CloudStorageException result = assertThrows(CloudStorageException.class, () -> { | ||
| uidCoreClient.download("https://core-prod.uidapi.com/sites/refresh"); | ||
| }); | ||
|
|
||
| assertAll( | ||
| () -> assertTrue(result.getMessage().contains("E12: Data Download Failure"), | ||
| "Should contain E12 error code"), | ||
| () -> assertTrue(result.getMessage().contains("exception: IOException"), | ||
| "Should log exception type"), | ||
| () -> assertTrue(result.getMessage().contains("Please visit UID2 guides for troubleshooting"), | ||
| "Should reference documentation") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what this "should" is... is that a message to customers as to what they should do? Let's not use "should" but instead just tell them what to do to remedy the error? There are additional instances of "should" line 185 and 187 also. And 171 and perhaps earlier. Maybe I'm misunderstanding. |
||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't generally say "please" in documentation.
People visit a site or a page but not a guide. Also, is it possible to include a link? If not a specific guide, you could link to the Private Operator overview page: https://unifiedid.com/docs/guides/integration-options-private-operator. Just a suggestion.
Suggestion for copy:
". For troubleshooting information, refer to the applicable Private Operator guide: see https://unifiedid.com/docs/guides/integration-options-private-operator.", e);
(not sure about that trailing "e" but it's your code, I trust you have it correct).