Errors during parsing of the error-message are wrapped
[facebook-errors] / src / main / java / de / juplo / facebook / errors / GraphApiErrorResponseErrorHandler.java
index 123c7f3..41f00fe 100644 (file)
@@ -87,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()
@@ -149,7 +142,5 @@ public class GraphApiErrorResponseErrorHandler implements ResponseErrorHandler
       parent.handleError(buffered);
       return;
     }
-
-    throw error;
   }
 }