Skip to content

Commit 3f1248a

Browse files
authored
Merge pull request #59 from psytester/patch-3
invokeAPI() --> ApiException() if non HTTP 200
2 parents acbe298 + 62d6f92 commit 3f1248a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/com/docusign/esign/client/ApiClient.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class ApiClient {
5757
private String basePath = "https://www.docusign.net/restapi";
5858
private boolean debugging = false;
5959
private int connectionTimeout = 0;
60+
private int readTimeout = 0;
6061

6162
private Client httpClient;
6263
private ObjectMapper mapper;
@@ -320,6 +321,24 @@ public ApiClient setConnectTimeout(int connectionTimeout) {
320321
return this;
321322
}
322323

324+
/**
325+
* Read timeout (in milliseconds).
326+
*/
327+
public int getReadTimeout() {
328+
return readTimeout;
329+
}
330+
331+
/**
332+
* Set the read timeout (in milliseconds).
333+
* A value of 0 means no timeout, otherwise values must be between 1 and
334+
* {@link Integer#MAX_VALUE}.
335+
*/
336+
public ApiClient setReadTimeout(int readTimeout) {
337+
this.readTimeout = readTimeout;
338+
httpClient.setReadTimeout(readTimeout);
339+
return this;
340+
}
341+
323342
/**
324343
* Get the date format used to parse/format date parameters.
325344
*/
@@ -746,6 +765,10 @@ public <T> T invokeAPI(String path, String method, List<Pair> queryParams, Objec
746765

747766
ClientResponse response = getAPIResponse(path, method, queryParams, body, headerParams, formParams, accept, contentType, authNames);
748767

768+
if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
769+
throw new ApiException("Error while requesting server, received HTTP code: " + response.getStatusInfo().getStatusCode() + " / with response Body: " + response.getEntity(String.class));
770+
}
771+
749772
statusCode = response.getStatusInfo().getStatusCode();
750773
responseHeaders = response.getHeaders();
751774

0 commit comments

Comments
 (0)