[java] Improving error message if a remote side responses with code 405 Method Not Allowed
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_INTERNAL_ERROR;
import static java.net.HttpURLConnection.HTTP_OK;
import static org.openqa.selenium.json.Json.MAP_TYPE;
@@ -87,9 +88,12 @@ public Response decode(HttpResponse encodedResponse) {
// {"error":"no such alert","message":"No tab modal was open when attempting to get the dialog text"}
if (HTTP_OK != encodedResponse.getStatus()) {
log.fine("Processing an error");
+ if (HTTP_BAD_METHOD == encodedResponse.getStatus()) {
+ response.setStatus(ErrorCodes.UNKNOWN_COMMAND);
+ response.setValue(content);
+ } else {
Map<String, Object> obj = json.toType(content, MAP_TYPE);
-
Object w3cWrappedValue = obj.get("value");
if (w3cWrappedValue instanceof Map && ((Map<?, ?>) w3cWrappedValue).containsKey("error")) {
//noinspection unchecked
@@ -124,6 +128,7 @@ public Response decode(HttpResponse encodedResponse) {
} else {
response.setValue(createException(error, message));
}
+ }
return response;
}
