def deserialize_ws_frame(self, payload): try: data = json.loads(payload) return ( data['method'], data.get('data') or {}, data.get('correlation_id'), ) except Exception: raise MalformedRequest('Invalid JSON data')
def test_handle_message_raise_malformed_request(container_factory, rabbit_config): container = container_factory(ExampleService, rabbit_config) container.start() with pytest.raises(MalformedRequest): with patch('nameko.rpc.RpcProvider.handle_message') as handle_message: handle_message.side_effect = MalformedRequest('bad request') with RpcProxy("exampleservice", rabbit_config) as proxy: proxy.task_a()
def handle_message(self, body, message): try: args = body['args'] kwargs = body['kwargs'] except KeyError: raise MalformedRequest('Message missing `args` or `kwargs`') self.check_signature(args, kwargs) context_data = self.unpack_message_headers(message) handle_result = partial(self.handle_result, message) try: self.container.spawn_worker(self, args, kwargs, context_data=context_data, handle_result=handle_result) except ContainerBeingKilled: self.rpc_consumer.requeue_message(message)