[java] Improving exception when server returns 504
Add a special case in W3CHttpResponseCodec handling 504 Gateway Time-out errors.
Before, the end user used to see a pretty unfriendly error:
> JsonException: Unable to determine type from: <. Last 1 characters read: <
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
+import static java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT;
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
-import static java.net.HttpURLConnection.HTTP_OK;
import static org.openqa.selenium.json.Json.MAP_TYPE;
import static org.openqa.selenium.json.Json.OBJECT_TYPE;
import static org.openqa.selenium.remote.http.Contents.string;
@@ -90,6 +90,9 @@ public Response decode(HttpResponse encodedResponse) {
if (HTTP_BAD_METHOD == encodedResponse.getStatus()) {
response.setStatus(ErrorCodes.UNKNOWN_COMMAND);
response.setValue(content);
+ } else if (HTTP_GATEWAY_TIMEOUT == encodedResponse.getStatus()) {
+ response.setStatus(ErrorCodes.UNHANDLED_ERROR);
+ response.setValue(content);
} else {
Map<String, Object> obj = json.toType(content, MAP_TYPE);
