X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Ffacebook%2Ferrors%2FGraphApiErrorResponseErrorHandler.java;h=41f00fe93ef255a6ebad61506ca7d809274a79e8;hb=8fc05fb4992fe6e34b39d10e9a3b053f42dea893;hp=ae6e2d503e270f7296dbd753034e93309693241a;hpb=2261ec7cb929b99f8f1d76385cca1b3b4692d7ab;p=facebook-errors diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java b/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java index ae6e2d5..41f00fe 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandler.java @@ -41,6 +41,11 @@ public class GraphApiErrorResponseErrorHandler implements ResponseErrorHandler private final ResponseErrorHandler parent; + public GraphApiErrorResponseErrorHandler() + { + this(null); + } + public GraphApiErrorResponseErrorHandler(ResponseErrorHandler errorHandler) { this.parent = @@ -82,24 +87,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() @@ -144,7 +142,5 @@ public class GraphApiErrorResponseErrorHandler implements ResponseErrorHandler parent.handleError(buffered); return; } - - throw error; } }