Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit c695255

Browse files
author
Chris Paul
authored
Merge pull request #65 from HelloFax/issue-64
Reset parameters, even if exception is thrown.
2 parents cac2432 + f0bc1c6 commit c695255

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.hellosign</groupId>
66
<artifactId>hellosign-java-sdk</artifactId>
77
<packaging>jar</packaging>
8-
<version>4.0.5</version>
8+
<version>4.0.6</version>
99
<name>HelloSign Java SDK</name>
1010
<url>https://github.com/HelloFax/hellosign-java-sdk</url>
1111
<properties>

src/main/java/com/hellosign/sdk/http/HttpClient.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ public JSONObject asJson() throws HelloSignException {
206206
json = new JSONObject(response);
207207
} catch (JSONException e) {
208208
throw new HelloSignException(e);
209+
} finally {
210+
reset();
209211
}
210212
validate(json);
211-
reset();
212213
return json;
213214
}
214215

@@ -222,14 +223,20 @@ public JSONObject asJson() throws HelloSignException {
222223
*/
223224
public File asFile(String fileName) throws HelloSignException {
224225
Integer lastResponseCode = getLastResponseCode();
225-
if (lastResponseCode != null && lastResponseCode != HttpURLConnection.HTTP_OK) {
226-
this.asJson(); // Will validate response
227-
}
228-
File f = createTemporaryFile(fileName);
229-
if (getLastResponseAsFile(f) == 0) {
230-
logger.warn("No bytes written to file: " + fileName);
226+
File f = null;
227+
try {
228+
if (lastResponseCode != null && lastResponseCode != HttpURLConnection.HTTP_OK) {
229+
this.asJson(); // Will validate response
230+
}
231+
f = createTemporaryFile(fileName);
232+
if (getLastResponseAsFile(f) == 0) {
233+
logger.warn("No bytes written to file: " + fileName);
234+
}
235+
} catch (HelloSignException ex) {
236+
throw ex;
237+
} finally {
238+
reset();
231239
}
232-
reset();
233240
return f;
234241
}
235242

0 commit comments

Comments
 (0)