diff --git a/src/main/java/com/braintreegateway/exceptions/TimeoutException.java b/src/main/java/com/braintreegateway/exceptions/TimeoutException.java new file mode 100644 index 00000000..3f981365 --- /dev/null +++ b/src/main/java/com/braintreegateway/exceptions/TimeoutException.java @@ -0,0 +1,13 @@ +package com.braintreegateway.exceptions; + +public class TimeoutException extends BraintreeException { + private static final long serialVersionUID = 1L; + + public TimeoutException(String message) { + super(message); + } + + public TimeoutException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/src/main/java/com/braintreegateway/util/Http.java b/src/main/java/com/braintreegateway/util/Http.java index 83b27d64..1def447d 100644 --- a/src/main/java/com/braintreegateway/util/Http.java +++ b/src/main/java/com/braintreegateway/util/Http.java @@ -5,6 +5,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; +import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLDecoder; import java.security.KeyStore; @@ -36,6 +37,7 @@ import com.braintreegateway.exceptions.DownForMaintenanceException; import com.braintreegateway.exceptions.NotFoundException; import com.braintreegateway.exceptions.ServerException; +import com.braintreegateway.exceptions.TimeoutException; import com.braintreegateway.exceptions.UnexpectedException; import com.braintreegateway.exceptions.UpgradeRequiredException; import com.braintreegateway.org.apache.commons.codec.binary.Base64; @@ -140,6 +142,8 @@ private NodeWrapper httpRequest(RequestMethod requestMethod, String url, String responseStream.close(); } } + } catch (SocketTimeoutException e) { + throw new TimeoutException(e.getMessage(), e); } catch (IOException e) { throw new UnexpectedException(e.getMessage(), e); } finally {