Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/main/java/com/microsoft/graph/http/GraphServiceException.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017 Microsoft Corporation
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -174,7 +174,7 @@ public String getResponseMessage() {
public String getMessage() {
return getMessage(verbose);
}

/**
* Gets the HTTP status code
*
Expand Down Expand Up @@ -215,7 +215,7 @@ public String getMethod() {
public String getUrl() {
return url;
}

/**
* Gets the request headers
* @return the request headers
Expand Down Expand Up @@ -255,12 +255,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);
Expand Down Expand Up @@ -402,7 +397,7 @@ public static <T> GraphServiceException createFromConnection(final IHttpRequest
error,
isVerbose);
}

/**
* Creates a Graph service exception from a given failed HTTP request
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ChunkedUploadResult(ClientException error) {
* @param exception The exception received from server.
*/
public ChunkedUploadResult(GraphServiceException exception) {
this(new ClientException(exception.getMessage(/* verbose */ true), exception));
this(new ClientException(exception.getMessage(), exception));
}

/**
Expand Down Expand Up @@ -122,4 +122,4 @@ public UploadSession getSession() {
public ClientException getError() {
return this.error;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testError() {
assertTrue(message.indexOf("truncated") > 0);
assertEquals(error,exception.getServiceError());
}

@Test
public void testVerboseError() {
GraphErrorResponse errorResponse = new GraphErrorResponse();
Expand Down Expand Up @@ -82,7 +82,7 @@ public Map<String, String> getHeaders() {
assertTrue(message.indexOf("Error code: Unable to parse error response message") == 0);
assertTrue(message.indexOf("http://localhost") > 0);
}

@Test
public void testNullConnection() {
DefaultLogger logger = new DefaultLogger();
Expand Down Expand Up @@ -124,5 +124,24 @@ public InputStream getInputStream() throws IOException {
assertTrue(message.indexOf("Error code: Unable to parse error response message") == 0);
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(null,null,new ArrayList<String>(),"requestPayload",401,"Unauthorized",new ArrayList<String>(),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(null,null,new ArrayList<String>(),"requestPayload",401,"Unauthorized",new ArrayList<String>(),errorResponse, true);
final String message = exception.getMessage();
assertTrue(message.indexOf("requestPayload") > 0);
}
}