/** * Responsible for handling an error response, including unmarshalling the error response * into the most specific exception type possible, and throwing the exception. * * @throws IOException If any problems are encountering reading the error response. */ private SdkException handleErrorResponse(SdkHttpFullResponse httpResponse, RequestExecutionContext context) throws IOException, InterruptedException { try { SdkException exception = errorResponseHandler.handle(httpResponse, context.executionAttributes()); exception.fillInStackTrace(); SdkStandardLogger.REQUEST_LOGGER.debug(() -> "Received error response: " + exception); return exception; } catch (InterruptedException | IOException e) { throw e; } catch (Exception e) { String errorMessage = String.format("Unable to unmarshall error response (%s). " + "Response Code: %d, Response Text: %s", e.getMessage(), httpResponse.statusCode(), httpResponse.statusText().orElse("null")); throw SdkClientException.builder().message(errorMessage).cause(e).build(); } }
/** * Handles a successful response from a service call by unmarshalling the results using the * specified response handler. * * @return The contents of the response, unmarshalled using the specified response handler. * @throws IOException If any problems were encountered reading the response contents from * the HTTP method object. */ private OutputT handleSuccessResponse(SdkHttpFullResponse httpResponse, RequestExecutionContext context) throws IOException, InterruptedException { try { SdkStandardLogger.REQUEST_LOGGER.debug(() -> "Received successful response: " + httpResponse.statusCode()); return successResponseHandler.handle(httpResponse, context.executionAttributes()); } catch (IOException | InterruptedException | RetryableException e) { throw e; } catch (Exception e) { if (e instanceof SdkException && ((SdkException) e).retryable()) { throw (SdkException) e; } String errorMessage = "Unable to unmarshall response (" + e.getMessage() + "). Response Code: " + httpResponse.statusCode() + ", Response Text: " + httpResponse.statusText().orElse(null); throw SdkClientException.builder().message(errorMessage).cause(e).build(); } }