@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; }
@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 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; }