Skip to content

Commit

Permalink
added logging for com.google.gson.stream.MalformedJsonException on lo…
Browse files Browse the repository at this point in the history
…gin attempt #66
  • Loading branch information
ktisha committed Jun 4, 2015
1 parent ce2fbfb commit 6abe7a2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/com/jetbrains/crucible/connection/CrucibleSessionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -157,7 +155,16 @@ protected JsonObject buildJsonResponse(@NotNull final String urlString) throws I
executeHttpMethod(method);

JsonParser parser = new JsonParser();
return parser.parse(new InputStreamReader(method.getResponseBodyAsStream(), Charset.forName("UTF-8"))).getAsJsonObject();
final String response = method.getResponseBodyAsString();

try {
return parser.parse(response).getAsJsonObject();
}
catch (JsonSyntaxException ex) {
LOG.error("Malformed Json");
LOG.error(response);
}
return new JsonObject();
}

private void executeHttpMethod(@NotNull HttpMethodBase method) throws IOException {
Expand All @@ -176,7 +183,15 @@ protected JsonObject buildJsonResponseForPost(@NotNull final String urlString,
method.setRequestEntity(requestEntity);
executeHttpMethod(method);
JsonParser parser = new JsonParser();
return parser.parse(new InputStreamReader(method.getResponseBodyAsStream(), Charset.forName("UTF-8"))).getAsJsonObject();
final String response = method.getResponseBodyAsString();
try {
return parser.parse(response).getAsJsonObject();
}
catch (JsonSyntaxException ex) {
LOG.error("Malformed Json");
LOG.error(response);
}
return new JsonObject();
}

protected void adjustHttpHeader(@NotNull final HttpMethod method) {
Expand Down

0 comments on commit 6abe7a2

Please sign in to comment.