/** * @param response The HTTP response. * @return the JSONErrorResponse object. * @throws IOException */ public static JsonErrorResponse fromResponse(HttpResponse response) throws IOException { int statusCode = response.getStatusCode(); // parse error body Map<String, String> map = JsonUtils.jsonToMap(new BufferedReader(new InputStreamReader( response.getContent(), StringUtils.UTF8))); /* * Services using AWS JSON 1.1 protocol with HTTP binding send the * error type information in the response headers, instead of the * content. */ String errorCode = response.getHeaders().get(X_AMZN_ERROR_TYPE); if (errorCode != null) { int separator = errorCode.indexOf(':'); if (separator != -1) { errorCode = errorCode.substring(0, separator); } } else if (map.containsKey("__type")) { // check body otherwise String type = map.get("__type"); int separator = type.lastIndexOf("#"); errorCode = type.substring(separator + 1); } return new JsonErrorResponse(statusCode, errorCode, map); } }
/** * @param response The HTTP response. * @return the JSONErrorResponse object. * @throws IOException */ public static JsonErrorResponse fromResponse(HttpResponse response) throws IOException { int statusCode = response.getStatusCode(); // parse error body Map<String, String> map = JsonUtils.jsonToMap(new BufferedReader(new InputStreamReader( response.getContent(), StringUtils.UTF8))); /* * Services using AWS JSON 1.1 protocol with HTTP binding send the * error type information in the response headers, instead of the * content. */ String errorCode = response.getHeaders().get(X_AMZN_ERROR_TYPE); if (errorCode != null) { int separator = errorCode.indexOf(':'); if (separator != -1) { errorCode = errorCode.substring(0, separator); } } else if (map.containsKey("__type")) { // check body otherwise String type = map.get("__type"); int separator = type.lastIndexOf("#"); errorCode = type.substring(separator + 1); } return new JsonErrorResponse(statusCode, errorCode, map); } }
/** * @param response The HTTP response. * @return the JSONErrorResponse object. * @throws IOException */ public static JsonErrorResponse fromResponse(HttpResponse response) throws IOException { int statusCode = response.getStatusCode(); // parse error body Map<String, String> map = JsonUtils.jsonToMap(new BufferedReader(new InputStreamReader( response.getContent(), StringUtils.UTF8))); /* * Services using AWS JSON 1.1 protocol with HTTP binding send the * error type information in the response headers, instead of the * content. */ String errorCode = response.getHeaders().get(X_AMZN_ERROR_TYPE); if (errorCode != null) { int separator = errorCode.indexOf(':'); if (separator != -1) { errorCode = errorCode.substring(0, separator); } } else if (map.containsKey("__type")) { // check body otherwise String type = map.get("__type"); int separator = type.lastIndexOf("#"); errorCode = type.substring(separator + 1); } return new JsonErrorResponse(statusCode, errorCode, map); } }