(self, message: dict, handler: RequestHandler)
| 428 | ) |
| 429 | |
| 430 | async def _dispatch_request(self, message: dict, handler: RequestHandler): |
| 431 | try: |
| 432 | params = message.get("params", {}) |
| 433 | outcome = handler(params) |
| 434 | if inspect.isawaitable(outcome): |
| 435 | outcome = await outcome |
| 436 | if outcome is not None and not isinstance( |
| 437 | outcome, dict | list | str | int | float | bool |
| 438 | ): |
| 439 | raise ValueError( |
| 440 | "Request handler must return a JSON-serializable value, " |
| 441 | f"got {type(outcome).__name__}" |
| 442 | ) |
| 443 | await self._send_response(message["id"], outcome) |
| 444 | except JsonRpcError as exc: |
| 445 | logger.debug( |
| 446 | "Error handling JSON-RPC method %s: %s", message.get("method", ""), exc.message |
| 447 | ) |
| 448 | await self._send_error_response(message["id"], exc.code, exc.message, exc.data) |
| 449 | except Exception as exc: # pylint: disable=broad-except |
| 450 | logger.debug( |
| 451 | "Error handling JSON-RPC method %s: %s", |
| 452 | message.get("method", ""), |
| 453 | str(exc), |
| 454 | exc_info=True, |
| 455 | ) |
| 456 | await self._send_error_response(message["id"], -32603, str(exc), None) |
| 457 | |
| 458 | async def _send_response(self, request_id: str, result: Any): |
| 459 | response = { |
no test coverage detected