diff --git a/src/main/java/com/docusign/esign/client/ApiClient.java b/src/main/java/com/docusign/esign/client/ApiClient.java index 7c5beba5..071a8428 100644 --- a/src/main/java/com/docusign/esign/client/ApiClient.java +++ b/src/main/java/com/docusign/esign/client/ApiClient.java @@ -57,6 +57,7 @@ public class ApiClient { private String basePath = "https://www.docusign.net/restapi"; private boolean debugging = false; private int connectionTimeout = 0; + private int readTimeout = 0; private Client httpClient; private ObjectMapper mapper; @@ -320,6 +321,24 @@ public ApiClient setConnectTimeout(int connectionTimeout) { return this; } + /** + * Read timeout (in milliseconds). + */ + public int getReadTimeout() { + return readTimeout; + } + + /** + * Set the read timeout (in milliseconds). + * A value of 0 means no timeout, otherwise values must be between 1 and + * {@link Integer#MAX_VALUE}. + */ + public ApiClient setReadTimeout(int readTimeout) { + this.readTimeout = readTimeout; + httpClient.setReadTimeout(readTimeout); + return this; + } + /** * Get the date format used to parse/format date parameters. */ @@ -746,6 +765,10 @@ public T invokeAPI(String path, String method, List queryParams, Objec ClientResponse response = getAPIResponse(path, method, queryParams, body, headerParams, formParams, accept, contentType, authNames); + if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { + throw new ApiException("Error while requesting server, received HTTP code: " + response.getStatusInfo().getStatusCode() + " / with response Body: " + response.getEntity(String.class)); + } + statusCode = response.getStatusInfo().getStatusCode(); responseHeaders = response.getHeaders();