Handle RESPONSE or ERROR message from relay server.
(self, response: dict[str, Any], command: str)
| 365 | ) |
| 366 | |
| 367 | def _handle_response(self, response: dict[str, Any], command: str) -> dict[str, Any]: |
| 368 | """Handle RESPONSE or ERROR message from relay server.""" |
| 369 | msg_type = response.get("type") |
| 370 | |
| 371 | if msg_type == "ERROR": |
| 372 | self._raise_error(response) |
| 373 | |
| 374 | if msg_type == "RESPONSE": |
| 375 | return self._handle_success_response(response, command) |
| 376 | |
| 377 | if msg_type == "INSTANCES": |
| 378 | data: dict[str, Any] = response.get("data", {}) |
| 379 | return data |
| 380 | |
| 381 | raise ProtocolError(f"Unexpected response type: {msg_type}", "PROTOCOL_ERROR") |
| 382 | |
| 383 | def _raise_error(self, response: dict[str, Any]) -> None: |
| 384 | """Raise appropriate exception from ERROR response.""" |