diff --git a/src/main/java/com/microsoft/graph/http/GraphServiceException.java b/src/main/java/com/microsoft/graph/http/GraphServiceException.java index d2718f6d4..4e9725fad 100644 --- a/src/main/java/com/microsoft/graph/http/GraphServiceException.java +++ b/src/main/java/com/microsoft/graph/http/GraphServiceException.java @@ -274,12 +274,7 @@ public String getMessage(final boolean verbose) { if (verbose) { sb.append(requestBody); } else { - final int bodyLength = Math.min(MAX_BREVITY_LENGTH, requestBody.length()); - final String truncatedBody = requestBody.substring(0, bodyLength); - sb.append(truncatedBody); - if (truncatedBody.length() == MAX_BREVITY_LENGTH) { - sb.append(TRUNCATION_MARKER); - } + sb.append(TRUNCATION_MARKER); } } sb.append(NEW_LINE).append(NEW_LINE); diff --git a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java index bbf2a53a4..ab839452b 100644 --- a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java +++ b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java @@ -92,7 +92,7 @@ protected LargeFileUploadResponse(@Nullable final ClientException error) { protected LargeFileUploadResponse(@Nonnull final GraphServiceException exception) { this(new ClientException(Objects .requireNonNull(exception, "parameter exception cannot be null") - .getMessage(/* verbose */ true), + .getMessage(), exception)); } diff --git a/src/test/java/com/microsoft/graph/http/GraphServiceExceptionTests.java b/src/test/java/com/microsoft/graph/http/GraphServiceExceptionTests.java index b2f577843..2e7bfff47 100644 --- a/src/test/java/com/microsoft/graph/http/GraphServiceExceptionTests.java +++ b/src/test/java/com/microsoft/graph/http/GraphServiceExceptionTests.java @@ -74,4 +74,24 @@ public void testcreateFromResponse() throws IOException { String message = exception.getMessage(); assertTrue(message.indexOf("http://localhost") > 0); } + @Test + public void requestPayloadShouldNotBePartOfMessageWhenNotVerbose(){ + final GraphErrorResponse errorResponse = new GraphErrorResponse(); + final GraphError error = new GraphError(); + error.code = GraphErrorCodes.UNAUTHENTICATED.toString(); + errorResponse.error = error; + final GraphServiceException exception = new GraphServiceException("GET","https://graph.microsoft.com/v1.0/me",new ArrayList(),"requestPayload",401,"Unauthorized",new ArrayList(),errorResponse, false); + final String message = exception.getMessage(); + assertFalse(message.indexOf("requestPayload") > 0); + } + @Test + public void requestPayloadShouldBePartOfMessageWhenVerbose(){ + final GraphErrorResponse errorResponse = new GraphErrorResponse(); + final GraphError error = new GraphError(); + error.code = GraphErrorCodes.UNAUTHENTICATED.toString(); + errorResponse.error = error; + final GraphServiceException exception = new GraphServiceException("GET","https://graph.microsoft.com/v1.0/me",new ArrayList(),"requestPayload",401,"Unauthorized",new ArrayList(),errorResponse, true); + final String message = exception.getMessage(); + assertTrue(message.indexOf("requestPayload") > 0); + } }