X-Git-Url: https://juplo.de/gitweb/?p=facebook-errors;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Ffacebook%2Ferrors%2FGraphApiErrorResponseErrorHandler.java;h=9df86a9dd2db187990b04f6e8229756b13563e50;hp=123c7f3d6a696bae2a3c23c2681b4006954ec774;hb=b05c51b4f7dc4bfe423a7ea306bf82f34eb0faf9;hpb=201cae17e8ce4face5f533bf03f050a146abb5c4 diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java b/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java index 123c7f3..9df86a9 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java @@ -55,27 +55,26 @@ public class GraphApiErrorResponseErrorHandler implements ResponseErrorHandler } + private boolean hasGraphApiError(ClientHttpResponse response) throws IOException + { + return HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series()); + } + @Override public boolean hasError(ClientHttpResponse response) throws IOException { - return - HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series()) - || this.parent.hasError(response); + return hasGraphApiError(response) || parent.hasError(response); } @Override public void handleError(final ClientHttpResponse response) throws IOException { - GraphApiErrorResponseErrorHandler.handleError(parent, response); - } + if (!hasGraphApiError(response)) + { + parent.handleError(response); + return; + } - public static void handleError( - final ResponseErrorHandler parent, - final ClientHttpResponse response - ) - throws - IOException - { if (response.getBody() == null) { // There is no body to interpret in the HTTP-message @@ -87,24 +86,17 @@ public class GraphApiErrorResponseErrorHandler implements ResponseErrorHandler final byte[] body = FileCopyUtils.copyToByteArray(response.getBody()); GraphApiException error; - try + error = GraphApiException.create(response.getStatusCode(), response.getHeaders(), body); + if (LOG.isInfoEnabled()) + LOG.info("error-response: {}", new String(body, Charset.forName("UTF-8"))); + if (!error.getClass().equals(ErrorResponseParsingErrorException.class)) { - error = GraphApiException.create(response.getStatusCode(), response.getHeaders(), body); - if (LOG.isInfoEnabled()) - LOG.info("error-response: {}", new String(body, Charset.forName("UTF-8"))); + throw error; } - catch (Exception e) + else { // The body of the HTTP-message could not be parsed. // Let the parent error-handler try to handle the response. - - LOG.warn( - "Could not convert the response into an exception, " + - "because the body is unparsable: error={}, body={}", - e.toString(), - new String(body, Charset.forName("UTF-8")) - ); - // To do so, we have to wrap the original response to fill in // the buffered body, if needed ClientHttpResponse buffered = new ClientHttpResponse() @@ -149,7 +141,5 @@ public class GraphApiErrorResponseErrorHandler implements ResponseErrorHandler parent.handleError(buffered); return; } - - throw error; } }