}
- @Override
- public boolean hasError(ClientHttpResponse response) throws IOException
+ private boolean hasGraphApiError(ClientHttpResponse response) throws IOException
{
return HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series());
}
@Override
- public void handleError(final ClientHttpResponse response) throws IOException
+ public boolean hasError(ClientHttpResponse response) throws IOException
{
- GraphApiErrorResponseErrorHandler.handleError(parent, response);
+ return hasGraphApiError(response) || parent.hasError(response);
}
- public static void handleError(
- final ResponseErrorHandler parent,
- final ClientHttpResponse response
- )
- throws
- IOException
+ @Override
+ public void handleError(final ClientHttpResponse response) throws IOException
{
+ if (!hasGraphApiError(response))
+ {
+ parent.handleError(response);
+ return;
+ }
+
if (response.getBody() == null)
{
// There is no body to interpret in the HTTP-message
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
{
LOG.info("testNoError");
- requestFactory.setBody("{\n" +
- " \"error\": {\n" +
- " \"message\": \"(#200) The user hasn't authorized the application to perform this action\",\n" +
- " \"type\": \"OAuthException\",\n" +
- " \"code\": 200\n" +
- " }\n" +
- "}");
+ requestFactory.setBody("{ \"message\": \"Hello World!\" }");
requestFactory.setStatus(HttpStatus.CONTINUE);
fail("Unexpected error: " + e);
}
+ requestFactory.setStatus(HttpStatus.BAD_REQUEST);
+ try
+ {
+ clientTemplate.getForObject("ANY", SOME.class);
+ fail("The parent handler should have raised an exception!");
+ }
+ catch(HttpClientErrorException e)
+ {
+ LOG.debug("Expexted error: {}", e.toString());
+ }
+ catch(Exception e)
+ {
+ LOG.debug("{}", e.toString());
+ fail("Unexpected error: " + e);
+ }
+
requestFactory.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
try
{
clientTemplate.getForObject("ANY", SOME.class);
+ fail("The parent handler should have raised an exception!");
+ }
+ catch(HttpServerErrorException e)
+ {
+ LOG.debug("Expexted error: {}", e.toString());
}
catch(Exception e)
{