Skip to content

Commit bbea0f2

Browse files
committed
[py] Check dict instance
1 parent ab9591a commit bbea0f2

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

py/selenium/webdriver/remote/errorhandler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def check_response(self, response: dict[str, Any]) -> None:
162162
if isinstance(status, int):
163163
value_json = response.get("value", None)
164164
if value_json and isinstance(value_json, str):
165-
if not value_json.isdigit():
166-
try:
167-
value = json.loads(value_json)
165+
try:
166+
value = json.loads(value_json)
167+
if isinstance(value, dict):
168168
if len(value) == 1:
169169
value = value["value"]
170170
status = value.get("error", None)
@@ -176,8 +176,8 @@ def check_response(self, response: dict[str, Any]) -> None:
176176
message = message.get("message")
177177
else:
178178
message = value.get("message", None)
179-
except ValueError:
180-
pass
179+
except ValueError:
180+
pass
181181

182182
exception_class: type[WebDriverException]
183183
e = ErrorCode()

py/test/unit/selenium/webdriver/remote/error_handler_tests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_relays_exception_stacktrace(handler, key):
259259
assert "Spam.ham" in e.value.stacktrace[0]
260260

261261

262-
def test_handle_errors_better(handler):
262+
def test_handle_json_error_with_message(handler):
263263
response = {
264264
"status": 500,
265265
"value": json.dumps(
@@ -281,21 +281,21 @@ def test_handle_errors_better(handler):
281281
assert "Could not start a new session." in e.value.msg
282282

283283

284-
def test_handle_numeric_value_error(handler):
284+
def test_handle_string_error(handler):
285285
response = {
286-
"status": 999,
287-
"value": "0",
286+
"status": 407,
287+
"value": "Proxy Authentication Required",
288288
}
289289
with pytest.raises(exceptions.WebDriverException) as e:
290290
handler.check_response(response)
291-
assert e.value.msg == "0"
291+
assert e.value.msg == "Proxy Authentication Required"
292292

293293

294-
def test_handle_non_json_error(handler):
294+
def test_handle_numeric_error(handler):
295295
response = {
296-
"status": 407,
297-
"value": "Proxy Authentication Required",
296+
"status": 999,
297+
"value": "0",
298298
}
299299
with pytest.raises(exceptions.WebDriverException) as e:
300300
handler.check_response(response)
301-
assert e.value.msg == "Proxy Authentication Required"
301+
assert e.value.msg == "0"

0 commit comments

Comments
 (0)