{"action":"created","comment":{"url":"https://api.github.com/repos/cloudant/java-cloudant/pulls/comments/42103963","id":42103963,"diff_hunk":"@@ -516,47 +516,30 @@ public InputStream executeToInputStream(HttpConnection connection) throws CouchD\n         }\r\n \r\n         try {\r\n-            JsonObject errorJsonMessage = null;\r\n-            if(cause != null && connection.getConnection().getErrorStream() != null) {\r\n-                String errorString = IOUtils.toString(connection.getConnection()\r\n-                        .getErrorStream(), \"UTF-8\");\r\n-                errorJsonMessage = gson.fromJson(errorString, JsonObject.class);\r\n-            }\r\n-\r\n-            //User errorStream to get error message if database does not exist or already exists\r\n-            String response = \"\";\r\n-            if(errorJsonMessage != null && errorJsonMessage.has(\"reason\")) {\r\n-                response = errorJsonMessage.toString();\r\n-            } else {\r\n-                response = connection.getConnection().getResponseMessage();\r\n-            }\r\n             code = connection.getConnection().getResponseCode();\r\n+            response = connection.getConnection().getResponseMessage();\r\n             // everything ok? return the stream\r\n             if (code / 100 == 2) { // success [200,299]\r\n                 return is;\r\n             } else if (code == 404) {\r\n                 throw new NoDocumentException(response, cause);\r\n             } else if(code == 412) {\r\n-                //Database already created\r\n-                return is;\r\n+                throw new PreconditionFailedException(response, cause);\r\n             } else {\r\n-                es = connection.getConnection().getErrorStream();\r\n-\r\n-                CouchDbException ex = getGson().fromJson(new InputStreamReader(es),\r\n-                        CouchDbException.class);\r\n-                if (ex == null && errorJsonMessage != null) {\r\n-                    //Try again with error json message\r\n-                    try {\r\n-                        ex = getGson().fromJson(errorJsonMessage,\r\n-                                CouchDbException.class);\r\n-                        ex.setStatusCode(code);\r\n-                    } catch (NullPointerException e) {\r\n-                        //Create new Exception from scratch\r\n+                CouchDbException ex = null;\r\n+                try {\r\n+                    es = connection.getConnection().getErrorStream();\r\n+                    ex = getGson().fromJson(new InputStreamReader(es),\r\n+                            CouchDbException.class);\r\n+                } catch(Exception e) {\r\n+                    ex = new CouchDbException(response, code);\r\n+                } finally {\r\n+                    if (ex == null) {\r","path":"src/main/java/com/cloudant/client/org/lightcouch/CouchDbClient.java","position":66,"original_position":66,"commit_id":"b16b1a6a25eacf9de20ac5998f80e83648e52c11","original_commit_id":"b16b1a6a25eacf9de20ac5998f80e83648e52c11","user":{"login":"tomblench","id":6302842,"avatar_url":"https://avatars.githubusercontent.com/u/6302842?v=3","gravatar_id":"","url":"https://api.github.com/users/tomblench","html_url":"https://github.com/tomblench","followers_url":"https://api.github.com/users/tomblench/followers","following_url":"https://api.github.com/users/tomblench/following{/other_user}","gists_url":"https://api.github.com/users/tomblench/gists{/gist_id}","starred_url":"https://api.github.com/users/tomblench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomblench/subscriptions","organizations_url":"https://api.github.com/users/tomblench/orgs","repos_url":"https://api.github.com/users/tomblench/repos","events_url":"https://api.github.com/users/tomblench/events{/privacy}","received_events_url":"https://api.github.com/users/tomblench/received_events","type":"User","site_admin":false},"body":"I thought about that - so just catch `Throwable` then","created_at":"2015-10-15T09:59:31Z","updated_at":"2015-10-15T09:59:31Z","html_url":"https://github.com/cloudant/java-cloudant/pull/111#discussion_r42103963","pull_request_url":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111","_links":{"self":{"href":"https://api.github.com/repos/cloudant/java-cloudant/pulls/comments/42103963"},"html":{"href":"https://github.com/cloudant/java-cloudant/pull/111#discussion_r42103963"},"pull_request":{"href":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111"}}},"pull_request":{"url":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111","id":47683513,"html_url":"https://github.com/cloudant/java-cloudant/pull/111","diff_url":"https://github.com/cloudant/java-cloudant/pull/111.diff","patch_url":"https://github.com/cloudant/java-cloudant/pull/111.patch","issue_url":"https://api.github.com/repos/cloudant/java-cloudant/issues/111","number":111,"state":"open","locked":false,"title":"Improve responseToInputStream exception handling","user":{"login":"emlaver","id":10552966,"avatar_url":"https://avatars.githubusercontent.com/u/10552966?v=3","gravatar_id":"","url":"https://api.github.com/users/emlaver","html_url":"https://github.com/emlaver","followers_url":"https://api.github.com/users/emlaver/followers","following_url":"https://api.github.com/users/emlaver/following{/other_user}","gists_url":"https://api.github.com/users/emlaver/gists{/gist_id}","starred_url":"https://api.github.com/users/emlaver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emlaver/subscriptions","organizations_url":"https://api.github.com/users/emlaver/orgs","repos_url":"https://api.github.com/users/emlaver/repos","events_url":"https://api.github.com/users/emlaver/events{/privacy}","received_events_url":"https://api.github.com/users/emlaver/received_events","type":"User","site_admin":false},"body":"*What*\r\nImprove CouchDbClient's `responseToInputStream` exception handling.\r\n\r\n*How*\r\nThrow `PreconditionFailedException` when response status code is 412.\r\n\r\nIn else block, if `fromJson` deserialization fails:\r\nCatch the exception and create a new `CouchDbException` with the response message and code. \r\n\r\nOr, if deserialization returns null:\r\nCreate a new `CouchDbException` in `finally` block.\r\n\r\nreviewer @ricellis\r\nreviewer @tomblench ","created_at":"2015-10-14T16:36:22Z","updated_at":"2015-10-15T09:59:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"228f838be67adebcf651a5cfc86792fbacf86f90","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111/commits","review_comments_url":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111/comments","review_comment_url":"https://api.github.com/repos/cloudant/java-cloudant/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudant/java-cloudant/issues/111/comments","statuses_url":"https://api.github.com/repos/cloudant/java-cloudant/statuses/b16b1a6a25eacf9de20ac5998f80e83648e52c11","head":{"label":"cloudant:48522-improve-exception-handling","ref":"48522-improve-exception-handling","sha":"b16b1a6a25eacf9de20ac5998f80e83648e52c11","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":22873328,"name":"java-cloudant","full_name":"cloudant/java-cloudant","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/java-cloudant","description":"A Java client for Cloudant","fork":false,"url":"https://api.github.com/repos/cloudant/java-cloudant","forks_url":"https://api.github.com/repos/cloudant/java-cloudant/forks","keys_url":"https://api.github.com/repos/cloudant/java-cloudant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/java-cloudant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/java-cloudant/teams","hooks_url":"https://api.github.com/repos/cloudant/java-cloudant/hooks","issue_events_url":"https://api.github.com/repos/cloudant/java-cloudant/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/java-cloudant/events","assignees_url":"https://api.github.com/repos/cloudant/java-cloudant/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/java-cloudant/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/java-cloudant/tags","blobs_url":"https://api.github.com/repos/cloudant/java-cloudant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/java-cloudant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/java-cloudant/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/java-cloudant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/java-cloudant/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/java-cloudant/languages","stargazers_url":"https://api.github.com/repos/cloudant/java-cloudant/stargazers","contributors_url":"https://api.github.com/repos/cloudant/java-cloudant/contributors","subscribers_url":"https://api.github.com/repos/cloudant/java-cloudant/subscribers","subscription_url":"https://api.github.com/repos/cloudant/java-cloudant/subscription","commits_url":"https://api.github.com/repos/cloudant/java-cloudant/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/java-cloudant/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/java-cloudant/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/java-cloudant/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/java-cloudant/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/java-cloudant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/java-cloudant/merges","archive_url":"https://api.github.com/repos/cloudant/java-cloudant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/java-cloudant/downloads","issues_url":"https://api.github.com/repos/cloudant/java-cloudant/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/java-cloudant/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/java-cloudant/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/java-cloudant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/java-cloudant/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/java-cloudant/releases{/id}","created_at":"2014-08-12T10:19:56Z","updated_at":"2015-08-29T22:23:01Z","pushed_at":"2015-10-14T16:36:22Z","git_url":"git://github.com/cloudant/java-cloudant.git","ssh_url":"git@github.com:cloudant/java-cloudant.git","clone_url":"https://github.com/cloudant/java-cloudant.git","svn_url":"https://github.com/cloudant/java-cloudant","homepage":null,"size":4243,"stargazers_count":14,"watchers_count":14,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":8,"forks":17,"open_issues":8,"watchers":14,"default_branch":"master"}},"base":{"label":"cloudant:feature-http-replacement","ref":"feature-http-replacement","sha":"4af10e09ea57510dea34c0b38ea67a2682712ad2","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":22873328,"name":"java-cloudant","full_name":"cloudant/java-cloudant","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/java-cloudant","description":"A Java client for Cloudant","fork":false,"url":"https://api.github.com/repos/cloudant/java-cloudant","forks_url":"https://api.github.com/repos/cloudant/java-cloudant/forks","keys_url":"https://api.github.com/repos/cloudant/java-cloudant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/java-cloudant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/java-cloudant/teams","hooks_url":"https://api.github.com/repos/cloudant/java-cloudant/hooks","issue_events_url":"https://api.github.com/repos/cloudant/java-cloudant/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/java-cloudant/events","assignees_url":"https://api.github.com/repos/cloudant/java-cloudant/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/java-cloudant/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/java-cloudant/tags","blobs_url":"https://api.github.com/repos/cloudant/java-cloudant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/java-cloudant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/java-cloudant/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/java-cloudant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/java-cloudant/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/java-cloudant/languages","stargazers_url":"https://api.github.com/repos/cloudant/java-cloudant/stargazers","contributors_url":"https://api.github.com/repos/cloudant/java-cloudant/contributors","subscribers_url":"https://api.github.com/repos/cloudant/java-cloudant/subscribers","subscription_url":"https://api.github.com/repos/cloudant/java-cloudant/subscription","commits_url":"https://api.github.com/repos/cloudant/java-cloudant/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/java-cloudant/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/java-cloudant/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/java-cloudant/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/java-cloudant/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/java-cloudant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/java-cloudant/merges","archive_url":"https://api.github.com/repos/cloudant/java-cloudant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/java-cloudant/downloads","issues_url":"https://api.github.com/repos/cloudant/java-cloudant/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/java-cloudant/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/java-cloudant/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/java-cloudant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/java-cloudant/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/java-cloudant/releases{/id}","created_at":"2014-08-12T10:19:56Z","updated_at":"2015-08-29T22:23:01Z","pushed_at":"2015-10-14T16:36:22Z","git_url":"git://github.com/cloudant/java-cloudant.git","ssh_url":"git@github.com:cloudant/java-cloudant.git","clone_url":"https://github.com/cloudant/java-cloudant.git","svn_url":"https://github.com/cloudant/java-cloudant","homepage":null,"size":4243,"stargazers_count":14,"watchers_count":14,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":8,"forks":17,"open_issues":8,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111"},"html":{"href":"https://github.com/cloudant/java-cloudant/pull/111"},"issue":{"href":"https://api.github.com/repos/cloudant/java-cloudant/issues/111"},"comments":{"href":"https://api.github.com/repos/cloudant/java-cloudant/issues/111/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudant/java-cloudant/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudant/java-cloudant/pulls/111/commits"},"statuses":{"href":"https://api.github.com/repos/cloudant/java-cloudant/statuses/b16b1a6a25eacf9de20ac5998f80e83648e52c11"}}}}