diff --git a/browserdebuggertools/exceptions.py b/browserdebuggertools/exceptions.py index be30736..40709a7 100644 --- a/browserdebuggertools/exceptions.py +++ b/browserdebuggertools/exceptions.py @@ -48,3 +48,7 @@ class UnknownError(ProtocolError): class MessagingThreadIsDeadError(DevToolsException): pass + + +class InvalidParametersError(ProtocolError): + pass diff --git a/browserdebuggertools/wssessionmanager.py b/browserdebuggertools/wssessionmanager.py index 92abd40..8a22b6b 100644 --- a/browserdebuggertools/wssessionmanager.py +++ b/browserdebuggertools/wssessionmanager.py @@ -18,7 +18,8 @@ from browserdebuggertools.exceptions import ( DevToolsException, ResultNotFoundError, TabNotFoundError, MaxRetriesException, DevToolsTimeoutException, DomainNotEnabledError, - MethodNotFoundError, UnknownError, ResourceNotFoundError, MessagingThreadIsDeadError + MethodNotFoundError, UnknownError, ResourceNotFoundError, MessagingThreadIsDeadError, + InvalidParametersError ) @@ -329,6 +330,8 @@ def execute(self, domain_name, method_name, params=None): raise ResourceNotFoundError(message) if code == -32601: raise MethodNotFoundError(message) + if code == -32602: + raise InvalidParametersError(message) raise UnknownError("DevTools Protocol error code %s: %s" % (code, message)) return result diff --git a/tests/unittests/test_wssessionmanager.py b/tests/unittests/test_wssessionmanager.py index 8150a15..5f5ef40 100644 --- a/tests/unittests/test_wssessionmanager.py +++ b/tests/unittests/test_wssessionmanager.py @@ -7,8 +7,8 @@ from browserdebuggertools.exceptions import ( DevToolsException, ResultNotFoundError, TabNotFoundError, - DomainNotEnabledError, DevToolsTimeoutException, MethodNotFoundError -) + DomainNotEnabledError, DevToolsTimeoutException, MethodNotFoundError, + InvalidParametersError) from browserdebuggertools.wssessionmanager import WSSessionManager, _WSMessagingThread MODULE_PATH = "browserdebuggertools.wssessionmanager." @@ -275,6 +275,16 @@ def test(self): "method": "%s.%s" % (domain, method), "params": {} }) + @patch(MODULE_PATH + "WSSessionManager._execute", new=MagicMock()) + def test_error(self): + + self.session_manager._wait_for_result = MagicMock( + return_value={"error": {"code": -32602, "message": "Invalid interceptionId"}} + ) + + with self.assertRaises(InvalidParametersError): + self.session_manager.execute(MagicMock(), MagicMock(), None) + class Test_WSSessionManager_add_domain(SessionManagerTest):