Skip to content

Commit d320a21

Browse files
committed
Unwrap errors from value field if present
The W3C spec says that all responses from the remote end should be set as a `value` field. I think most people thought that this didn't apply to errors, but they would think wrong. It does. *sigh* Geckodriver 0.15 follows the W3C spec more closely, and so correctly wraps the error in the `value` property of the returned JSON. Handle this nicely.
1 parent 06d52b5 commit d320a21

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

java/client/src/org/openqa/selenium/remote/http/W3CHttpResponseCodec.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static java.net.HttpURLConnection.HTTP_OK;
2323

2424
import com.google.common.base.Strings;
25+
import com.google.gson.JsonElement;
2526
import com.google.gson.JsonObject;
2627
import com.google.gson.JsonParser;
2728

@@ -78,6 +79,11 @@ public Response decode(HttpResponse encodedResponse) {
7879
log.fine("Processing an error");
7980
JsonObject obj = new JsonParser().parse(content).getAsJsonObject();
8081

82+
JsonElement w3cWrappedValue = obj.get("value");
83+
if (w3cWrappedValue instanceof JsonObject && ((JsonObject) w3cWrappedValue).has("error")) {
84+
obj = (JsonObject) w3cWrappedValue;
85+
}
86+
8187
String message = "An unknown error has occurred";
8288
if (obj.has("message")) {
8389
message = obj.get("message").getAsString();

0 commit comments

Comments
 (0)