@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("InvalidLambdaFunctionOutputException"); }
/** * @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); } }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonErrorResponse error; try { error = JsonErrorResponse.fromResponse(response); } catch (IOException e) { throw new AmazonClientException("Unable to parse error response", e); } AmazonServiceException ase = runErrorUnmarshallers(error); if (ase == null) return null; ase.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) { ase.setErrorType(ErrorType.Client); } else { ase.setErrorType(ErrorType.Service); } ase.setErrorCode(error.getErrorCode()); for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) { ase.setRequestId(headerEntry.getValue()); } } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonErrorResponse error; try { error = JsonErrorResponse.fromResponse(response); } catch (IOException e) { throw new AmazonClientException("Unable to parse error response", e); } AmazonServiceException ase = runErrorUnmarshallers(error); if (ase == null) return null; ase.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) { ase.setErrorType(ErrorType.Client); } else { ase.setErrorType(ErrorType.Service); } ase.setErrorCode(error.getErrorCode()); for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) { ase.setRequestId(headerEntry.getValue()); } } return ase; }
/** * Subclass should override the match(String, JSONObject) method to indicate * whether it represents the given error type, and unmarshall(JSONObject) * should never return null. */ @Override public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception { String message = error.getMessage(); String errorCode = error.getErrorCode(); if ((null == message || message.isEmpty()) && (null == errorCode || errorCode.isEmpty())) { /** * Trigger the catch block in AmazonHttpClient.handleErrorResponse * to handle 413 and 503 errors */ throw new AmazonClientException( "Neither error message nor error code is found in the error response payload."); } else { AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); return ase; } }
/** * Subclass should override the match(String, JSONObject) method to indicate * whether it represents the given error type, and unmarshall(JSONObject) * should never return null. */ @Override public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception { String message = error.getMessage(); String errorCode = error.getErrorCode(); if ((null == message || message.isEmpty()) && (null == errorCode || errorCode.isEmpty())) { /** * Trigger the catch block in AmazonHttpClient.handleErrorResponse * to handle 413 and 503 errors */ throw new AmazonClientException( "Neither error message nor error code is found in the error response payload."); } else { AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); return ase; } }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonErrorResponse error; try { error = JsonErrorResponse.fromResponse(response); } catch (IOException e) { throw new AmazonClientException("Unable to parse error response", e); } AmazonServiceException ase = runErrorUnmarshallers(error); if (ase == null) return null; ase.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) { ase.setErrorType(ErrorType.Client); } else { ase.setErrorType(ErrorType.Service); } ase.setErrorCode(error.getErrorCode()); for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) { ase.setRequestId(headerEntry.getValue()); } } return ase; }
/** * Subclass should override the match(String, JSONObject) method to indicate * whether it represents the given error type, and unmarshall(JSONObject) * should never return null. */ @Override public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception { String message = error.getMessage(); String errorCode = error.getErrorCode(); if ((null == message || message.isEmpty()) && (null == errorCode || errorCode.isEmpty())) { /** * Trigger the catch block in AmazonHttpClient.handleErrorResponse * to handle 413 and 503 errors */ throw new AmazonClientException( "Neither error message nor error code is found in the error response payload."); } else { AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); return ase; } }
@Test public void testJsonExceptionUnmarshallerWithAdditionalFields() throws Exception { HttpResponse response = HttpResponse.builder() .content(new ByteArrayInputStream(errorResponse.getBytes("UTF-8"))) .build(); JsonErrorResponse error = JsonErrorResponse.fromResponse(response); AmazonServiceException ase = new InternalServerErrorExceptionUnmarshaller() .unmarshall(error); assertTrue(ase instanceof InternalServerErrorException); assertEquals("value1", ((InternalServerErrorException) ase).getField1()); assertEquals("value2", ((InternalServerErrorException) ase).getField2()); assertEquals("InternalServerError", ase.getErrorCode()); assertEquals("Requested resource not found " + "(Service: null; " + "Status Code: 0; " + "Error Code: InternalServerError; " + "Request ID: null)", ase.getMessage()); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("AccessDeniedException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("ResourceNotFoundException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("ResourceAlreadyExistsException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("ExpiredImportTokenException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("InvalidS3BucketException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("ResourceNotFoundException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("ConcurrentModificationException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("InvalidConfigurationException"); }
@Override public boolean match(JsonErrorResponse error) throws Exception { return error.getErrorCode().equals("ContinuousBackupsUnavailableException"); }