use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException in project cloudbreak by hortonworks.
the class JaxRSUtilTest method testClusterProxyError.
@Test
public void testClusterProxyError() {
when(response.getStatusInfo()).thenReturn(statusType);
when(statusType.getFamily()).thenReturn(Family.SERVER_ERROR);
when(statusType.getStatusCode()).thenReturn(599);
when(statusType.getReasonPhrase()).thenReturn("Network connect timeout");
when(response.readEntity(any(Class.class))).thenReturn("{\"status\":599,\"code\":\"cluster-proxy.proxy.timeout\",\"message\":" + "\"Connect timeout of Some(10 seconds) expired\",\"retryable\":true}");
WebApplicationException cpException = assertThrows(ClusterProxyWebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
assertTrue(cpException instanceof ClusterProxyWebApplicationException);
when(response.readEntity(any(Class.class))).thenReturn("{\"status\":599,\"code\":\"cluster-proxy.proxy.timeout\",\"message\":" + "\"Connect timeout of Some(10 seconds) expired\",\"retryable\":false}");
cpException = assertThrows(WebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
assertFalse(cpException instanceof ClusterProxyWebApplicationException);
when(response.readEntity(any(Class.class))).thenReturn("{\"random\":true}");
cpException = assertThrows(WebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
assertFalse(cpException instanceof ClusterProxyWebApplicationException);
when(response.readEntity(any(Class.class))).thenReturn("not a json");
cpException = assertThrows(WebApplicationException.class, () -> JaxRSUtil.response(response, GenericResponses.class));
assertFalse(cpException instanceof ClusterProxyWebApplicationException);
}
use of com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException in project cloudbreak by hortonworks.
the class JaxRSUtil method handleUnexpectedError.
private static WebApplicationException handleUnexpectedError(Response response) {
String textResponse = response.readEntity(String.class);
LOGGER.debug("Received error: {}", textResponse);
String errorMessage = transformErrorMessage(textResponse);
String errormsg = "Status: " + response.getStatusInfo().getStatusCode() + ' ' + response.getStatusInfo().getReasonPhrase() + " Response: " + errorMessage;
try {
if (JsonUtil.isValid(errorMessage)) {
ClusterProxyError clusterProxyError = JsonUtil.jsonToType(errorMessage, ClusterProxyErrorTypeReference.get());
if (clusterProxyError.getRetryable()) {
return new ClusterProxyWebApplicationException(errormsg, clusterProxyError);
}
}
} catch (IllegalArgumentException e) {
LOGGER.trace("Error message is not a json or not a cluster proxy error, thus we cannot parse it.", e);
}
return new WebApplicationException(errormsg);
}
Aggregations