{"action":"created","issue":{"url":"https://api.github.com/repos/hazelcast/hazelcast-aws/issues/56","repository_url":"https://api.github.com/repos/hazelcast/hazelcast-aws","labels_url":"https://api.github.com/repos/hazelcast/hazelcast-aws/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast-aws/issues/56/comments","events_url":"https://api.github.com/repos/hazelcast/hazelcast-aws/issues/56/events","html_url":"https://github.com/hazelcast/hazelcast-aws/issues/56","id":300648856,"number":56,"title":"AWS client does not retrieve error reasons","user":{"login":"vertex-github","id":6462117,"avatar_url":"https://avatars0.githubusercontent.com/u/6462117?v=4","gravatar_id":"","url":"https://api.github.com/users/vertex-github","html_url":"https://github.com/vertex-github","followers_url":"https://api.github.com/users/vertex-github/followers","following_url":"https://api.github.com/users/vertex-github/following{/other_user}","gists_url":"https://api.github.com/users/vertex-github/gists{/gist_id}","starred_url":"https://api.github.com/users/vertex-github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vertex-github/subscriptions","organizations_url":"https://api.github.com/users/vertex-github/orgs","repos_url":"https://api.github.com/users/vertex-github/repos","events_url":"https://api.github.com/users/vertex-github/events{/privacy}","received_events_url":"https://api.github.com/users/vertex-github/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-27T14:20:24Z","updated_at":"2018-02-27T14:25:55Z","closed_at":null,"author_association":"NONE","body":"When AWS issues an error they do so under the `503` error code.  The current AWS client does not retrieve the text content of error messages as an Exception is thrown when the response code is not 2xx or 3xx.  The following patch attempts to retrieve and log the error reason:\r\n\r\n```\r\nIndex: src/main/java/com/hazelcast/aws/impl/DescribeInstances.java\r\n\r\nIDEA additional info:\r\n\r\nSubsystem: com.intellij.openapi.diff.impl.patch.CharsetEP\r\n\r\n<+>UTF-8\r\n\r\n===================================================================\r\n\r\n--- src/main/java/com/hazelcast/aws/impl/DescribeInstances.java            (revision 2b2fa219a4cf12892a1b914bef98f2caca10d24a)\r\n\r\n+++ src/main/java/com/hazelcast/aws/impl/DescribeInstances.java         (date 1519741021000)\r\n\r\n@@ -23,10 +23,14 @@\r\n\r\nimport com.hazelcast.com.eclipsesource.json.JsonObject;\r\n\r\nimport com.hazelcast.config.AwsConfig;\r\n\r\nimport com.hazelcast.config.InvalidConfigurationException;\r\n\r\n+import com.hazelcast.logging.ILogger;\r\n\r\n+import com.hazelcast.logging.Logger;\r\n\r\n+import com.hazelcast.nio.IOUtil;\r\n\r\n\r\n import java.io.BufferedReader;\r\n\r\nimport java.io.IOException;\r\n\r\nimport java.io.InputStream;\r\n\r\n+import java.io.InputStreamReader;\r\n\r\nimport java.net.HttpURLConnection;\r\n\r\nimport java.net.URL;\r\n\r\nimport java.text.SimpleDateFormat;\r\n\r\n@@ -52,7 +56,9 @@\r\n\r\n  */\r\n\r\npublic class DescribeInstances {\r\n\r\n\r\n-    /**\r\n\r\n+             private static final ILogger LOGGER = Logger.getLogger( DescribeInstances.class );\r\n\r\n+\r\n\r\n+             /**\r\n\r\n      * URI to fetch container credentials (when IAM role is enabled)\r\n\r\n      *\r\n\r\n      * see http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html\r\n\r\n@@ -241,7 +247,50 @@\r\n\r\n         httpConnection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(awsConfig.getConnectionTimeoutSeconds()));\r\n\r\n         httpConnection.setDoOutput(false);\r\n\r\n         httpConnection.connect();\r\n\r\n-        return httpConnection.getInputStream();\r\n\r\n+\r\n\r\n+                 InputStream is = null;\r\n\r\n+                 try\r\n\r\n+                 {\r\n\r\n+                                 is = httpConnection.getInputStream();\r\n\r\n+                 }\r\n\r\n+                 catch( IOException e )\r\n\r\n+                 {\r\n\r\n+                                 LOGGER.warning( \"Unable to retrieve info from URL: \" + httpConnection.getResponseCode() );\r\n\r\n+                                 InputStream errorStream = httpConnection.getErrorStream();\r\n\r\n+                                 String errorMsg = inputStreamToString( errorStream );\r\n\r\n+                                             LOGGER.warning( \"Error Message: \" + errorMsg );\r\n\r\n+\r\n\r\n+                                             throw e;\r\n\r\n+                 }\r\n\r\n+\r\n\r\n+                 return is;\r\n\r\n+    }\r\n\r\n+\r\n\r\n+    private String inputStreamToString( InputStream is )\r\n\r\n+    {\r\n\r\n+                 StringBuilder buf = new StringBuilder();\r\n\r\n+\r\n\r\n+                 BufferedReader br = null;\r\n\r\n+                 try\r\n\r\n+                 {\r\n\r\n+                                 br = new BufferedReader( new InputStreamReader( is, \"UTF-8\" ) );\r\n\r\n+\r\n\r\n+                                 String line;\r\n\r\n+                                 while( (line = br.readLine()) != null )\r\n\r\n+                                 {\r\n\r\n+                                                 buf.append( line );\r\n\r\n+                                 }\r\n\r\n+                 }\r\n\r\n+                 catch( IOException e )\r\n\r\n+                 {\r\n\r\n+                                 LOGGER.warning( \"Unable to retrieve error stream response\", e );\r\n\r\n+                 }\r\n\r\n+                 finally\r\n\r\n+                 {\r\n\r\n+                                 IOUtil.closeResource( br );\r\n\r\n+                 }\r\n\r\n+\r\n\r\n+                 return buf.toString();\r\n\r\n     }\r\n\r\n\r\n     public EC2RequestSigner getRequestSigner() {\r\n```"},"comment":{"url":"https://api.github.com/repos/hazelcast/hazelcast-aws/issues/comments/368894770","html_url":"https://github.com/hazelcast/hazelcast-aws/issues/56#issuecomment-368894770","issue_url":"https://api.github.com/repos/hazelcast/hazelcast-aws/issues/56","id":368894770,"user":{"login":"vertex-github","id":6462117,"avatar_url":"https://avatars0.githubusercontent.com/u/6462117?v=4","gravatar_id":"","url":"https://api.github.com/users/vertex-github","html_url":"https://github.com/vertex-github","followers_url":"https://api.github.com/users/vertex-github/followers","following_url":"https://api.github.com/users/vertex-github/following{/other_user}","gists_url":"https://api.github.com/users/vertex-github/gists{/gist_id}","starred_url":"https://api.github.com/users/vertex-github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vertex-github/subscriptions","organizations_url":"https://api.github.com/users/vertex-github/orgs","repos_url":"https://api.github.com/users/vertex-github/repos","events_url":"https://api.github.com/users/vertex-github/events{/privacy}","received_events_url":"https://api.github.com/users/vertex-github/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T14:25:55Z","updated_at":"2018-02-27T14:25:55Z","author_association":"NONE","body":"Server side error codes and message format detailed here: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html#api-error-codes-table-server"}}
{"actor":{"display_login":"vertex-github"}}