From 8cf7908a8b77b010e714192909a689b31a4f2989 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 29 Jul 2013 12:10:30 +0400 Subject: [PATCH] Github: throw exception on bad HTTP response status code --- .../plugins/github/api/GithubApiUtil.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 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 83d24840e804..3aa17805186e 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java @@ -212,14 +212,22 @@ public class GithubApiUtil { return client; } - private static void checkStatusCode(@NotNull HttpMethod method) throws GithubAuthenticationException { - switch (method.getStatusCode()) { - case 400: // HTTP_BAD_REQUEST - case 401: // HTTP_UNAUTHORIZED - case 402: // HTTP_PAYMENT_REQUIRED - case 403: // HTTP_FORBIDDEN - case 404: // HTTP_NOT_FOUND + private static void checkStatusCode(@NotNull HttpMethod method) throws IOException { + int code = method.getStatusCode(); + switch (code) { + case HttpStatus.SC_OK: + case HttpStatus.SC_CREATED: + 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: + case HttpStatus.SC_NOT_FOUND: throw new GithubAuthenticationException("Request response: " + getErrorMessage(method)); + default: + throw new HttpException(code + ": " + method.getStatusText()); } }