projects
/
facebook-errors
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d4becb1
)
Added helpful logging-statements to GraphApiErrorHandler
author
Kai Moritz
<kai@juplo.de>
Sat, 7 Nov 2015 15:07:09 +0000
(16:07 +0100)
committer
Kai Moritz
<kai@juplo.de>
Tue, 10 Nov 2015 14:51:19 +0000
(15:51 +0100)
src/main/java/de/juplo/facebook/client/GraphApiErrorHandler.java
patch
|
blob
|
history
diff --git
a/src/main/java/de/juplo/facebook/client/GraphApiErrorHandler.java
b/src/main/java/de/juplo/facebook/client/GraphApiErrorHandler.java
index
a8b2d28
..
6b1ab97
100644
(file)
--- a/
src/main/java/de/juplo/facebook/client/GraphApiErrorHandler.java
+++ b/
src/main/java/de/juplo/facebook/client/GraphApiErrorHandler.java
@@
-4,6
+4,9
@@
import de.juplo.facebook.exceptions.GraphApiException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
@@
-31,6
+34,9
@@
import org.springframework.web.client.ResponseErrorHandler;
*/
public class GraphApiErrorHandler implements ResponseErrorHandler
{
*/
public class GraphApiErrorHandler implements ResponseErrorHandler
{
+ private final static Logger LOG =
+ LoggerFactory.getLogger(GraphApiErrorHandler.class);
+
private final ResponseErrorHandler parent;
private final ResponseErrorHandler parent;
@@
-54,6
+60,7
@@
public class GraphApiErrorHandler implements ResponseErrorHandler
if (!HttpStatus.BAD_REQUEST.equals(response.getStatusCode()))
{
// We will only handle 400 BAD REQUEST
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;
}
parent.handleError(response);
return;
}
@@
-62,6
+69,7
@@
public class GraphApiErrorHandler implements ResponseErrorHandler
if (response.getBody() == null)
{
// There is no body to interpret in the HTTP-message
if (response.getBody() == null)
{
// There is no body to interpret in the HTTP-message
+ LOG.warn("Could not convert the response into an exception, because there is no message-body.");
parent.handleError(response);
return;
}
parent.handleError(response);
return;
}
@@
-72,12
+80,16
@@
public class GraphApiErrorHandler implements ResponseErrorHandler
try
{
error = GraphApiException.create(body);
try
{
error = GraphApiException.create(body);
+ if (LOG.isInfoEnabled())
+ LOG.info("error-response: {}", new String(body, Charset.forName("UTF-8")));
}
catch (Exception e)
{
// The body of the HTTP-message could not be parsed.
// Let the parent error-handler try to handle the response.
}
catch (Exception e)
{
// 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);
+
// To do so, we have to wrap the original response to fill in
// the buffered body, if needed
ClientHttpResponse buffered = new ClientHttpResponse()
// To do so, we have to wrap the original response to fill in
// the buffered body, if needed
ClientHttpResponse buffered = new ClientHttpResponse()