Skip to content

Commit 46e4397

Browse files
author
sathish Ramesh
committed
fix: handle external timeout error with status code 531
1 parent f65f1ed commit 46e4397

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

http/src/main/java/com/mx/path/connect/http/HttpClientFilter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.EOFException;
44
import java.io.IOException;
55
import java.io.UnsupportedEncodingException;
6+
import java.net.SocketTimeoutException;
67
import java.net.URISyntaxException;
78
import java.time.LocalDate;
89
import java.time.LocalDateTime;
@@ -42,6 +43,7 @@
4243
import org.apache.http.client.entity.UrlEncodedFormEntity;
4344
import org.apache.http.client.methods.RequestBuilder;
4445
import org.apache.http.client.utils.URIBuilder;
46+
import org.apache.http.conn.ConnectTimeoutException;
4547
import org.apache.http.conn.HttpHostConnectException;
4648
import org.apache.http.conn.ssl.NoopHostnameVerifier;
4749
import org.apache.http.entity.ByteArrayEntity;
@@ -65,6 +67,7 @@ public class HttpClientFilter extends RequestFilterBase {
6567
* instead of converting it to a String.
6668
*/
6769
private static final List<String> RAW_BODY_CONTENT_TYPE_HINTS = Arrays.asList("image", "pdf", "msword");
70+
private static final int HTTP_STATUS_EXTERNAL_TIMEOUT = 531;
6871

6972
private static GsonBuilder gsonBuilder = new GsonBuilder();
7073
private static final Gson GSON = gsonBuilder
@@ -157,6 +160,12 @@ public final void execute(Request request, Response response) {
157160
} finally {
158161
response.finish();
159162
}
163+
} catch (ConnectTimeoutException e) {
164+
httpResponse.setStatus(HttpStatus.valueOf(HTTP_STATUS_EXTERNAL_TIMEOUT));
165+
throw new ConnectException("Connection timeout: " + e.getMessage(), e);
166+
} catch (SocketTimeoutException e) {
167+
httpResponse.setStatus(HttpStatus.valueOf(HTTP_STATUS_EXTERNAL_TIMEOUT));
168+
throw new ConnectException("Read timeout: " + e.getMessage(), e);
160169
} catch (SSLHandshakeException e) {
161170
throw new HttpClientConnectException("SSL handshake failed", e);
162171
} catch (SSLException e) {

0 commit comments

Comments
 (0)