Skip to content

Commit

Permalink
Throw a more meaningful exception when a connection is reset while pa…
Browse files Browse the repository at this point in the history
…rsing the result
  • Loading branch information
veena-udayabhanu committed Sep 11, 2013
1 parent 69c7811 commit f26734f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.SocketException;

import javax.xml.stream.XMLStreamException;

Expand Down Expand Up @@ -89,7 +90,12 @@ public static StorageException translateException(final HttpURLConnection reques
int responseCode = 0;
try {
responseCode = request.getResponseCode();
responseMessage = request.getResponseMessage();
if (cause instanceof SocketException) {
responseMessage = request.getResponseMessage();
}
else {
responseMessage = cause.getMessage();
}
}
catch (final IOException e) {
// ignore errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
Expand All @@ -34,6 +35,7 @@
import com.microsoft.windowsazure.services.core.storage.RetryPolicyFactory;
import com.microsoft.windowsazure.services.core.storage.RetryResult;
import com.microsoft.windowsazure.services.core.storage.SendingRequestEvent;
import com.microsoft.windowsazure.services.core.storage.StorageErrorCode;
import com.microsoft.windowsazure.services.core.storage.StorageErrorCodeStrings;
import com.microsoft.windowsazure.services.core.storage.StorageException;
import com.microsoft.windowsazure.services.core.storage.utils.Utility;
Expand Down Expand Up @@ -169,10 +171,20 @@ public static <CLIENT_TYPE, PARENT_TYPE, RESULT_TYPE> RESULT_TYPE executeWithRet
}
catch (final XMLStreamException e) {
// Non Retryable except when the inner exception is actually an IOException
translatedException = StorageException
.translateException(getLastRequestObject(opContext), e, opContext);

// Only in the case of xml exceptions that are due to connection issues.
if (e.getCause() instanceof SocketException) {
translatedException = new StorageException(StorageErrorCode.SERVICE_INTERNAL_ERROR.toString(),
"An unknown failure occurred : ".concat(e.getCause().getMessage()),
HttpURLConnection.HTTP_INTERNAL_ERROR, null, e);
}
else {
translatedException = StorageException.translateException(getLastRequestObject(opContext), e,
opContext);
}

task.getResult().setException(translatedException);
if (!(e.getCause() instanceof IOException)) {
if (!(e.getCause() instanceof IOException) && !(e.getCause() instanceof SocketException)) {
throw translatedException;
}
}
Expand Down

0 comments on commit f26734f

Please sign in to comment.