Skip to content

Commit

Permalink
fix: handle Connection Exception and socket exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sathish Ramesh authored and Sathish1891 committed Jan 27, 2025
1 parent 64821f9 commit b91af79
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.EOFException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.time.LocalDate;
Expand Down Expand Up @@ -44,6 +45,7 @@
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.entity.ByteArrayEntity;
Expand Down Expand Up @@ -159,8 +161,8 @@ public final void execute(Request request, Response response) {
} finally {
response.finish();
}
} catch (ConnectException e) {
throw new HttpClientConnectException("Connection Exception", e);
} catch (ConnectTimeoutException e) {
throw new HttpClientConnectException("Connection timeout Exception", e);
} catch (SocketTimeoutException e) {
throw new HttpClientConnectException("Read Timeout Exception", e);
} catch (NoHttpResponseException e) {
Expand All @@ -173,6 +175,10 @@ public final void execute(Request request, Response response) {
throw new HttpClientConnectException("Host closed connection", e);
} catch (HttpHostConnectException e) {
throw new HttpClientConnectException("Host connection failed", e);
} catch (SocketException e) {
throw new HttpClientConnectException("Socket connection reset", e);
} catch (ConnectException e) {
throw new HttpClientConnectException("Connection Exception", e);
} catch (IOException e) {
throw new ConnectException("HttpClient Execute failed: " + e.getMessage(), e);
}
Expand Down

0 comments on commit b91af79

Please sign in to comment.