Skip to content

Commit

Permalink
Adding ActivityId(rid) in Excpetion
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj Modi committed Aug 30, 2023
1 parent 39eaf8d commit 77e2bb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,22 @@ private static String formatMessage(final AbfsHttpOperation abfsHttpOperation) {
// HEAD request response doesn't have StorageErrorCode, StorageErrorMessage.
if (abfsHttpOperation.getMethod().equals("HEAD")) {
return String.format(
"Operation failed: \"%1$s\", %2$s, HEAD, %3$s",
abfsHttpOperation.getStatusDescription(),
abfsHttpOperation.getStatusCode(),
abfsHttpOperation.getMaskedUrl());
"Operation failed: \"%1$s\", %2$s, HEAD, %3$ss, rId: %4$s",
abfsHttpOperation.getStatusDescription(),
abfsHttpOperation.getStatusCode(),
abfsHttpOperation.getMaskedUrl(),
abfsHttpOperation.getRequestId());
}

return String.format(
"Operation failed: \"%1$s\", %2$s, %3$s, %4$s, %5$s, \"%6$s\"",
abfsHttpOperation.getStatusDescription(),
abfsHttpOperation.getStatusCode(),
abfsHttpOperation.getMethod(),
abfsHttpOperation.getMaskedUrl(),
abfsHttpOperation.getStorageErrorCode(),
// Remove break line to ensure the request id and timestamp can be shown in console.
abfsHttpOperation.getStorageErrorMessage().replaceAll("\\n", " "));
"Operation failed: \"%1$s\", %2$s, %3$s, %4$s, rId: %5$s, %6$s, \"%7$s\"",
abfsHttpOperation.getStatusDescription(),
abfsHttpOperation.getStatusCode(),
abfsHttpOperation.getMethod(),
abfsHttpOperation.getMaskedUrl(),
abfsHttpOperation.getRequestId(),
abfsHttpOperation.getStorageErrorCode(),
// Remove break line to ensure the request id and timestamp can be shown in console.
abfsHttpOperation.getStorageErrorMessage().replaceAll("\\n", " "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
String errorMessage = ex.getLocalizedMessage();
String[] errorFields = errorMessage.split(",");

Assert.assertEquals(4, errorFields.length);
// Expected Fields are: Message, StatusCode, Method, URL, ActivityId(rId)
Assert.assertEquals(5, errorFields.length);
// Check status message, status code, HTTP Request Type and URL.
Assert.assertEquals("Operation failed: \"The specified path does not exist.\"", errorFields[0].trim());
Assert.assertEquals("404", errorFields[1].trim());
Assert.assertEquals("HEAD", errorFields[2].trim());
Assert.assertTrue(errorFields[3].trim().startsWith("http"));
Assert.assertTrue(errorFields[4].trim().startsWith("rId:"));
}

try {
Expand All @@ -76,16 +78,17 @@ public void testAbfsRestOperationExceptionFormat() throws IOException {
String[] errorFields = errorMessage.split(",");
Assertions.assertThat(errorFields)
.describedAs("fields in exception of %s", ex)
.hasSize(6);
.hasSize(7);
// Check status message, status code, HTTP Request Type and URL.
Assert.assertEquals("Operation failed: \"The specified path does not exist.\"", errorFields[0].trim());
Assert.assertEquals("404", errorFields[1].trim());
Assert.assertEquals("GET", errorFields[2].trim());
Assert.assertTrue(errorFields[3].trim().startsWith("http"));
Assert.assertTrue(errorFields[4].trim().startsWith("rId:"));
// Check storage error code and storage error message.
Assert.assertEquals("PathNotFound", errorFields[4].trim());
Assert.assertTrue(errorFields[5].contains("RequestId")
&& errorFields[5].contains("Time"));
Assert.assertEquals("PathNotFound", errorFields[5].trim());
Assert.assertTrue(errorFields[6].contains("RequestId")
&& errorFields[6].contains("Time"));
}
}

Expand Down

0 comments on commit 77e2bb8

Please sign in to comment.