use of com.microsoft.graph.core.GraphErrorCodes in project msgraph-sdk-java by microsoftgraph.
the class DefaultHttpProviderTests method testVerboseErrorResponse.
@Test
public void testVerboseErrorResponse() throws Exception {
final GraphErrorCodes expectedErrorCode = GraphErrorCodes.INVALID_REQUEST;
final String expectedMessage = "Test error!";
final GraphErrorResponse toSerialize = new GraphErrorResponse();
toSerialize.error = new GraphError();
toSerialize.error.code = expectedErrorCode.toString();
toSerialize.error.message = expectedMessage;
toSerialize.error.innererror = null;
JsonObject raw = new JsonObject();
raw.add("response", new JsonPrimitive("The raw request was invalid"));
toSerialize.rawObject = raw;
MockLogger logger = new MockLogger();
logger.setLoggingLevel(LoggerLevel.DEBUG);
mProvider = new DefaultHttpProvider(new MockSerializer(toSerialize, ""), mAuthenticationProvider = new MockAuthenticationProvider(), new MockExecutors(), logger);
final ITestConnectionData data = new ITestConnectionData() {
@Override
public int getRequestCode() {
return 415;
}
@Override
public String getJsonResponse() {
return "{}";
}
@Override
public Map<String, String> getHeaders() {
return new HashMap<>();
}
};
mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
try {
mProvider.send(new MockHttpRequest(), DriveItem.class, null);
fail("Expected exception in previous statement");
} catch (final GraphServiceException e) {
assertFalse(e.getMessage().indexOf("truncated") > 0);
assertTrue(e.getMessage().indexOf("The raw request was invalid") > 0);
}
}
use of com.microsoft.graph.core.GraphErrorCodes in project msgraph-sdk-java by microsoftgraph.
the class DefaultHttpProviderTests method testErrorResponse.
@Test
public void testErrorResponse() throws Exception {
final GraphErrorCodes expectedErrorCode = GraphErrorCodes.INVALID_REQUEST;
final String expectedMessage = "Test error!";
final GraphErrorResponse toSerialize = new GraphErrorResponse();
toSerialize.error = new GraphError();
toSerialize.error.code = expectedErrorCode.toString();
toSerialize.error.message = expectedMessage;
toSerialize.error.innererror = null;
setDefaultHttpProvider(toSerialize);
final ITestConnectionData data = new ITestConnectionData() {
@Override
public int getRequestCode() {
return 415;
}
@Override
public String getJsonResponse() {
return "{}";
}
@Override
public Map<String, String> getHeaders() {
return new HashMap<>();
}
};
mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
try {
mProvider.send(new MockHttpRequest(), DriveItem.class, null);
fail("Expected exception in previous statement");
} catch (final GraphServiceException e) {
assertTrue(e.getMessage().indexOf("truncated") > 0);
assertEquals(expectedMessage, e.getServiceError().message);
}
}
Aggregations