static Exception convert(BatchResultErrorEntry be) { AmazonServiceException toReturn = new AmazonServiceException(be.getMessage()); toReturn.setErrorCode(be.getCode()); toReturn.setErrorType(be.isSenderFault() ? ErrorType.Client : ErrorType.Service); toReturn.setServiceName("AmazonSQS"); return toReturn; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { final AmazonServiceException ase = handleAse(response); ase.setStatusCode(response.getStatusCode()); ase.setServiceName(response.getRequest().getServiceName()); awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId()) .addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode()) .addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode()); return ase; }
private AmazonServiceException handleAse(HttpResponse response) throws Exception { final int statusCode = response.getStatusCode(); try { return delegate.handle(response); } catch(InterruptedException e) { throw e; } catch (Exception e) { // If the errorResponseHandler doesn't work, then check for error responses that don't have any content if (statusCode == 413) { AmazonServiceException exception = new AmazonServiceException("Request entity too large"); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Client); exception.setErrorCode("Request entity too large"); return exception; } else if (statusCode >= 500 && statusCode < 600) { AmazonServiceException exception = new AmazonServiceException(response.getStatusText()); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Service); exception.setErrorCode(response.getStatusText()); return exception; } else { throw e; } } }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }
static Exception convert(BatchResultErrorEntry be) { AmazonServiceException toReturn = new AmazonServiceException(be.getMessage()); toReturn.setErrorCode(be.getCode()); toReturn.setErrorType(be.isSenderFault() ? ErrorType.Client : ErrorType.Service); toReturn.setServiceName("AmazonSQS"); return toReturn; }
exception.setServiceName(request.getServiceName()); exception.setStatusCode(HTTP_STATUS_REQ_TOO_LONG); exception.setErrorType(ErrorType.Client); && "Service Unavailable".equalsIgnoreCase(response.getStatusText())) { exception = new AmazonServiceException("Service unavailable"); exception.setServiceName(request.getServiceName()); exception.setStatusCode(HTTP_STATUS_SERVICE_UNAVAILABLE); exception.setErrorType(ErrorType.Service); exception.setServiceName(request.getServiceName()); exception.fillInStackTrace(); return exception;
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { final AmazonServiceException ase = handleAse(response); ase.setStatusCode(response.getStatusCode()); ase.setServiceName(response.getRequest().getServiceName()); awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId()) .addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode()) .addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode()); return ase; }
private AmazonServiceException handleAse(HttpResponse response) throws Exception { final int statusCode = response.getStatusCode(); try { return delegate.handle(response); } catch(InterruptedException e) { throw e; } catch (Exception e) { // If the errorResponseHandler doesn't work, then check for error responses that don't have any content if (statusCode == 413) { AmazonServiceException exception = new AmazonServiceException("Request entity too large"); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Client); exception.setErrorCode("Request entity too large"); return exception; } else if (statusCode >= 500 && statusCode < 600) { AmazonServiceException exception = new AmazonServiceException(response.getStatusText()); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Service); exception.setErrorCode(response.getStatusText()); return exception; } else { throw e; } } }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); AmazonServiceException ase = new AmazonServiceException("Test"); ase.setErrorCode("TestError"); ase.setErrorType(ErrorType.Service); ase.setServiceName(request.getServiceName()); ase.setStatusCode(response.getStatusCode()); return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }
static AmazonServiceException amazonServiceException(Exception exception, String serviceName, int statusCode) { if (exception instanceof AmazonServiceException) { return (AmazonServiceException) exception; } final AmazonServiceException ase = new AmazonServiceException(exception.getMessage(), exception); ase.setStatusCode(statusCode); ase.setErrorCode(DEFAULT_UNKNOWN); ase.setServiceName(serviceName); ase.setErrorType(AmazonServiceException.ErrorType.Unknown); return ase; } }
AmazonServiceException ex = new AmazonServiceException("400 Bad Request -- Edda could not find one of the managed objects requested.", e); ex.setStatusCode(400); ex.setServiceName(serviceName); ex.setErrorType(AmazonServiceException.ErrorType.Unknown); throw ex;
public AmazonServiceException handle(HttpResponse response) throws Exception { JSONObject jsonBody = getBodyAsJson(response); Class<? extends AmazonServiceException> exceptionClass = exceptionClasses.get(response.getStatusCode()); AmazonServiceException result; // Support other attribute names for the message? // TODO: Inspect exception type (caching details) and apply other values from the body String message = jsonBody.has("message") ? jsonBody.getString("message") : jsonBody.getString("Message"); if (exceptionClass != null) { result = exceptionClass.getConstructor(String.class).newInstance(message); } else { result = AmazonServiceException.class.getConstructor(String.class).newInstance(message); } result.setServiceName(response.getRequest().getServiceName()); result.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < 500) { result.setErrorType(ErrorType.Client); } else { result.setErrorType(ErrorType.Service); } for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if (headerEntry.getKey().equalsIgnoreCase("X-Amzn-RequestId")) { result.setRequestId(headerEntry.getValue()); } } return result; }
static Exception convert(BatchResultErrorEntry be) { AmazonServiceException toReturn = new AmazonServiceException(be.getMessage()); toReturn.setErrorCode(be.getCode()); toReturn.setErrorType(be.isSenderFault() ? ErrorType.Client : ErrorType.Service); toReturn.setServiceName("AmazonSQS"); return toReturn; }
static Exception convert(BatchResultErrorEntry be) { AmazonServiceException toReturn = new AmazonServiceException(be.getMessage()); toReturn.setErrorCode(be.getCode()); toReturn.setErrorType(be.isSenderFault() ? ErrorType.Client : ErrorType.Service); toReturn.setServiceName("AmazonSQS"); return toReturn; }
/** * After determining the transformation in the API specific transform method, this helper method sets the * transformed exception's fields to match the original exception. If no transformation occurred, the original * exception is returned. * * @param original The original DynamoDB Streams exception * @param transformed The equivalent Kinesis exception that needs its fields updated * @return The final result of the transformation ready to be thrown by the adapter */ private static AmazonServiceException applyFields(AmazonServiceException original, AmazonServiceException transformed) { if (transformed == null) { LOG.error("Could not transform a DynamoDB AmazonServiceException to a compatible Kinesis exception", original); return original; } // Here we update the transformed exception fields with the original exception values if (original.getErrorCode() != null) { transformed.setErrorCode(original.getErrorCode()); } // Null is transformed to UNKNOWN, so a null value is impossible. transformed.setErrorType(original.getErrorType()); if (original.getRequestId() != null) { transformed.setRequestId(original.getRequestId()); } if (original.getServiceName() != null) { transformed.setServiceName(original.getServiceName()); } transformed.setStatusCode(original.getStatusCode()); LOG.error(String.format("DynamoDB Streams exception: %s tranformed to Kinesis %s", original.getClass(), transformed.getClass()), original); return transformed; }
/** * After determining the transformation in the API specific transform method, this helper method sets the * transformed exception's fields to match the original exception. If no transformation occurred, the original * exception is returned. * * @param original The original DynamoDB Streams exception * @param transformed The equivalent Kinesis exception that needs its fields updated * @return The final result of the transformation ready to be thrown by the adapter */ private static AmazonServiceException applyFields(AmazonServiceException original, AmazonServiceException transformed) { if (transformed == null) { LOG.error("Could not transform a DynamoDB AmazonServiceException to a compatible Kinesis exception", original); return original; } // Here we update the transformed exception fields with the original exception values if (original.getErrorCode() != null) { transformed.setErrorCode(original.getErrorCode()); } // Null is transformed to UNKNOWN, so a null value is impossible. transformed.setErrorType(original.getErrorType()); if (original.getRequestId() != null) { transformed.setRequestId(original.getRequestId()); } if (original.getServiceName() != null) { transformed.setServiceName(original.getServiceName()); } transformed.setStatusCode(original.getStatusCode()); LOG.error(String.format("DynamoDB Streams exception: %s tranformed to Kinesis %s", original.getClass(), transformed.getClass()), original); return transformed; }
private AmazonServiceException handleAse(HttpResponse response) throws Exception { final int statusCode = response.getStatusCode(); try { return delegate.handle(response); } catch(InterruptedException e) { throw e; } catch (Exception e) { // If the errorResponseHandler doesn't work, then check for error responses that don't have any content if (statusCode == 413) { AmazonServiceException exception = new AmazonServiceException("Request entity too large"); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Client); exception.setErrorCode("Request entity too large"); return exception; } else if (statusCode >= 500 && statusCode < 600) { AmazonServiceException exception = new AmazonServiceException(response.getStatusText()); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Service); exception.setErrorCode(response.getStatusText()); return exception; } else { throw e; } } }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { final AmazonServiceException ase = handleAse(response); ase.setStatusCode(response.getStatusCode()); ase.setServiceName(response.getRequest().getServiceName()); awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId()) .addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode()) .addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode()); return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }