File tree Expand file tree Collapse file tree 1 file changed +21
-8
lines changed
src/main/java/com/sendgrid Expand file tree Collapse file tree 1 file changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -278,18 +278,20 @@ public Response delete(Request request) throws URISyntaxException, IOException {
278278 }
279279
280280 private Response executeApiCall (HttpRequestBase httpPost ) throws IOException {
281- CloseableHttpResponse serverResponse = httpClient .execute (httpPost );
282281 try {
283- Response response = getResponse (serverResponse );
284- if (response .getStatusCode () >= 300 ) {
285- //throwing IOException here to not break API behavior.
286- throw new IOException ("Request returned status Code " +response .getStatusCode ()+"Body:" +response .getBody ());
282+ CloseableHttpResponse serverResponse = httpClient .execute (httpPost );
283+ try {
284+ Response response = getResponse (serverResponse );
285+ if (response .getStatusCode () >= 300 ) {
286+ //throwing IOException here to not break API behavior.
287+ throw new IOException ("Request returned status Code " +response .getStatusCode ()+"Body:" +response .getBody ());
288+ }
289+ return response ;
290+ } finally {
291+ serverResponse .close ();
287292 }
288- return response ;
289293 } catch (ClientProtocolException e ) {
290294 throw new IOException (e .getMessage ());
291- } finally {
292- serverResponse .close ();
293295 }
294296 }
295297
@@ -323,4 +325,15 @@ public Response api(Request request) throws IOException {
323325 throw new IOException (errors .toString ());
324326 }
325327 }
328+
329+ @ Override
330+ public void finalize () throws Throwable {
331+ try {
332+ this .httpClient .close ();
333+ } catch (IOException e ) {
334+ throw new Throwable (e .getMessage ());
335+ } finally {
336+ super .finalize ();
337+ }
338+ }
326339}
You can’t perform that action at this time.
0 commit comments