Skip to content

Commit 886811a

Browse files
authored
Merge pull request #166 from microsoftgraph/bugfix/error-log-verbosity
- fixes a bug where errors would log payload even on error verbosity
2 parents 6d496db + 9cfcce3 commit 886811a

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/main/java/com/microsoft/graph/http/GraphServiceException.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,7 @@ public String getMessage(final boolean verbose) {
274274
if (verbose) {
275275
sb.append(requestBody);
276276
} else {
277-
final int bodyLength = Math.min(MAX_BREVITY_LENGTH, requestBody.length());
278-
final String truncatedBody = requestBody.substring(0, bodyLength);
279-
sb.append(truncatedBody);
280-
if (truncatedBody.length() == MAX_BREVITY_LENGTH) {
281-
sb.append(TRUNCATION_MARKER);
282-
}
277+
sb.append(TRUNCATION_MARKER);
283278
}
284279
}
285280
sb.append(NEW_LINE).append(NEW_LINE);

src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected LargeFileUploadResponse(@Nullable final ClientException error) {
9292
protected LargeFileUploadResponse(@Nonnull final GraphServiceException exception) {
9393
this(new ClientException(Objects
9494
.requireNonNull(exception, "parameter exception cannot be null")
95-
.getMessage(/* verbose */ true),
95+
.getMessage(),
9696
exception));
9797
}
9898

src/test/java/com/microsoft/graph/http/GraphServiceExceptionTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,24 @@ public void testcreateFromResponse() throws IOException {
7474
String message = exception.getMessage();
7575
assertTrue(message.indexOf("http://localhost") > 0);
7676
}
77+
@Test
78+
public void requestPayloadShouldNotBePartOfMessageWhenNotVerbose(){
79+
final GraphErrorResponse errorResponse = new GraphErrorResponse();
80+
final GraphError error = new GraphError();
81+
error.code = GraphErrorCodes.UNAUTHENTICATED.toString();
82+
errorResponse.error = error;
83+
final GraphServiceException exception = new GraphServiceException("GET","https://graph.microsoft.com/v1.0/me",new ArrayList<String>(),"requestPayload",401,"Unauthorized",new ArrayList<String>(),errorResponse, false);
84+
final String message = exception.getMessage();
85+
assertFalse(message.indexOf("requestPayload") > 0);
86+
}
87+
@Test
88+
public void requestPayloadShouldBePartOfMessageWhenVerbose(){
89+
final GraphErrorResponse errorResponse = new GraphErrorResponse();
90+
final GraphError error = new GraphError();
91+
error.code = GraphErrorCodes.UNAUTHENTICATED.toString();
92+
errorResponse.error = error;
93+
final GraphServiceException exception = new GraphServiceException("GET","https://graph.microsoft.com/v1.0/me",new ArrayList<String>(),"requestPayload",401,"Unauthorized",new ArrayList<String>(),errorResponse, true);
94+
final String message = exception.getMessage();
95+
assertTrue(message.indexOf("requestPayload") > 0);
96+
}
7797
}

0 commit comments

Comments
 (0)