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
13 changes: 11 additions & 2 deletions src/main/java/com/microsoft/graph/content/BatchResponseStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import com.microsoft.graph.http.GraphErrorResponse;
import com.microsoft.graph.http.GraphFatalServiceException;
import com.microsoft.graph.http.GraphServiceException;
import com.microsoft.graph.logger.ILogger;
import com.microsoft.graph.logger.LoggerLevel;
import com.microsoft.graph.serializer.DefaultSerializer;
import com.microsoft.graph.serializer.ISerializer;

/** Response for the batch step */
Expand Down Expand Up @@ -61,7 +64,13 @@ public <T2> T2 getDeserializedBody(@Nonnull final Class<T2> resultClass) throws
final GraphErrorResponse error = serializer.deserializeObject((JsonElement)body, GraphErrorResponse.class);
if(error == null || error.error == null) {
return serializer.deserializeObject((JsonElement)body, resultClass);
} else
throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, false);
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a unit test possible for this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! there you go. :)

boolean verboseError = false;
if(serializer instanceof DefaultSerializer) {
final ILogger logger = ((DefaultSerializer)serializer).getLogger();
verboseError = logger != null && logger.getLoggingLevel() == LoggerLevel.DEBUG;
}
throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, verboseError);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ public Class<?> getDerivedClass(@Nonnull final JsonObject jsonObject, @Nullable
*
* @return a logger
*/
@VisibleForTesting
@Nullable
public ILogger getLogger() {
return logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import com.google.gson.JsonElement;
import com.microsoft.graph.http.GraphErrorResponse;
import com.microsoft.graph.http.GraphServiceException;
import com.microsoft.graph.logger.DefaultLogger;
import com.microsoft.graph.logger.ILogger;
import com.microsoft.graph.logger.LoggerLevel;
import com.microsoft.graph.serializer.DefaultSerializer;
import com.microsoft.graph.serializer.ISerializer;

Expand Down Expand Up @@ -114,4 +116,52 @@ public void deserializesErrorsProperly() {
} else
fail("batch response was null");
}
@Test
public void includeVerboseInformation() {
String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}";
ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{
setLoggingLevel(LoggerLevel.DEBUG);
}});
BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
if(batchresponse != null) {
if(batchresponse.responses != null) // this is done by the batch request in the fluent API
for(final BatchResponseStep<?> step : batchresponse.responses) {
step.serializer = serializer;
}
try {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
} catch(GraphServiceException ex) {
final GraphErrorResponse response = ex.getError();
assertNotNull(response);
assertNotNull(response.error);
assertNotNull(response.error.message);
assertEquals(ex.getMessage(true), ex.getMessage());
}
} else
fail("batch response was null");
}
@Test
public void doesNotIncludeVerboseInformation() {
String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}";
ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{
setLoggingLevel(LoggerLevel.ERROR);
}});
BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
if(batchresponse != null) {
if(batchresponse.responses != null) // this is done by the batch request in the fluent API
for(final BatchResponseStep<?> step : batchresponse.responses) {
step.serializer = serializer;
}
try {
batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
} catch(GraphServiceException ex) {
final GraphErrorResponse response = ex.getError();
assertNotNull(response);
assertNotNull(response.error);
assertNotNull(response.error.message);
assertEquals(ex.getMessage(false), ex.getMessage());
}
} else
fail("batch response was null");
}
}