|
25 | 25 | import static org.openqa.selenium.json.Json.OBJECT_TYPE;
|
26 | 26 | import static org.openqa.selenium.remote.http.Contents.string;
|
27 | 27 |
|
28 |
| -import java.lang.reflect.Constructor; |
29 | 28 | import java.util.Map;
|
30 | 29 | import java.util.Objects;
|
31 | 30 | import java.util.Optional;
|
@@ -99,12 +98,15 @@ public Response decode(HttpResponse encodedResponse) {
|
99 | 98 | response.setStatus(ErrorCodes.UNHANDLED_ERROR);
|
100 | 99 | response.setValue(content);
|
101 | 100 | } else {
|
102 |
| - Map<String, Object> obj = json.toType(content, MAP_TYPE); |
| 101 | + Map<String, Object> org = json.toType(content, MAP_TYPE); |
| 102 | + Map<String, Object> obj; |
103 | 103 |
|
104 |
| - Object w3cWrappedValue = obj.get("value"); |
| 104 | + Object w3cWrappedValue = org.get("value"); |
105 | 105 | if (w3cWrappedValue instanceof Map && ((Map<?, ?>) w3cWrappedValue).containsKey("error")) {
|
106 | 106 | //noinspection unchecked
|
107 | 107 | obj = (Map<String, Object>) w3cWrappedValue;
|
| 108 | + } else { |
| 109 | + obj = org; |
108 | 110 | }
|
109 | 111 |
|
110 | 112 | String message = "An unknown error has occurred";
|
@@ -133,7 +135,7 @@ public Response decode(HttpResponse encodedResponse) {
|
133 | 135 | }
|
134 | 136 | response.setValue(new UnhandledAlertException(message, text));
|
135 | 137 | } else {
|
136 |
| - response.setValue(createException(error, message)); |
| 138 | + response.setValue(errorCodec.decode(org)); |
137 | 139 | }
|
138 | 140 | }
|
139 | 141 | return response;
|
@@ -178,15 +180,4 @@ protected Response reconstructValue(Response response) {
|
178 | 180 | response.setValue(elementConverter.apply(response.getValue()));
|
179 | 181 | return response;
|
180 | 182 | }
|
181 |
| - |
182 |
| - private WebDriverException createException(String error, String message) { |
183 |
| - Class<? extends WebDriverException> clazz = errorCodes.getExceptionType(error); |
184 |
| - |
185 |
| - try { |
186 |
| - Constructor<? extends WebDriverException> constructor = clazz.getConstructor(String.class); |
187 |
| - return constructor.newInstance(message); |
188 |
| - } catch (ReflectiveOperationException e) { |
189 |
| - throw new WebDriverException(message); |
190 |
| - } |
191 |
| - } |
192 | 183 | }
|
0 commit comments