From dda5341c98508b05fd94e1e186bb394eca9e659d Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Sat, 19 Apr 2014 12:16:08 +0400 Subject: [PATCH] Github: log invalid requests --- .../jetbrains/plugins/github/api/GithubApiUtil.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java index 1d7bbfd20979..9029cd86181e 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -111,7 +111,7 @@ public class GithubApiUtil { String uri = GithubUrlUtil.getApiUrl(auth.getHost()) + path; method = doREST(auth, uri, requestBody, headers, verb); - checkStatusCode(method); + checkStatusCode(method, requestBody); InputStream resp = method.getResponseBodyAsStream(); if (resp == null) { @@ -235,7 +235,7 @@ public class GithubApiUtil { return client; } - private static void checkStatusCode(@NotNull HttpMethod method) throws IOException { + private static void checkStatusCode(@NotNull HttpMethod method, @Nullable String body) throws IOException { int code = method.getStatusCode(); switch (code) { case HttpStatus.SC_OK: @@ -243,7 +243,6 @@ public class GithubApiUtil { case HttpStatus.SC_ACCEPTED: case HttpStatus.SC_NO_CONTENT: return; - case HttpStatus.SC_BAD_REQUEST: case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_PAYMENT_REQUIRED: case HttpStatus.SC_FORBIDDEN: @@ -261,6 +260,12 @@ public class GithubApiUtil { } throw new GithubAuthenticationException("Request response: " + message); + case HttpStatus.SC_BAD_REQUEST: + case HttpStatus.SC_UNPROCESSABLE_ENTITY: + if (body != null) { + LOG.info(body); + } + throw new GithubStatusCodeException(code + ": " + getErrorMessage(method), code); default: throw new GithubStatusCodeException(code + ": " + getErrorMessage(method), code); } @@ -440,7 +445,7 @@ public class GithubApiUtil { String uri = GithubUrlUtil.getApiUrl(auth.getHost()) + "/user"; method = doREST(auth, uri, null, Collections.
emptyList(), HttpVerb.HEAD); - checkStatusCode(method); + checkStatusCode(method, null); Header header = method.getResponseHeader("X-OAuth-Scopes"); if (header == null) {