The body is printed out readable, if an exception occures during parsing
[facebook-errors] / src / main / java / de / juplo / facebook / errors / GraphApiErrorHandler.java
index 13a93e8..fe2932c 100644 (file)
@@ -57,15 +57,16 @@ public class GraphApiErrorHandler implements ResponseErrorHandler
   @Override
   public void handleError(final ClientHttpResponse response) throws IOException
   {
-    if (!HttpStatus.BAD_REQUEST.equals(response.getStatusCode()))
-    {
-      // We will only handle 400 BAD REQUEST
-      LOG.debug("ignoring response with status-code {}.", response.getStatusCode());
-      parent.handleError(response);
-      return;
-    }
-
+    GraphApiErrorHandler.handleError(parent, response);
+  }
 
+  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
@@ -88,7 +89,12 @@ public class GraphApiErrorHandler implements ResponseErrorHandler
       // 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: {}", body);
+      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