Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
roflcoopter committed Jun 11, 2024
1 parent 3e81453 commit 7d48c90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions viseron/components/webserver/websocket_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,31 @@ async def handle_message(self, message) -> None:
try:
handler(self, schema(message))
except Exception as err: # pylint: disable=broad-except
await self.handle_exception(command_id, err)
await self.handle_exception(command_id, message, err)
self._last_id = command_id

async def handle_exception(self, command_id, err: Exception) -> None:
async def handle_exception(self, command_id, message, err: Exception) -> None:
"""Handle an exception."""
log_handler = LOGGER.error

if isinstance(err, vol.Invalid):
code = WS_ERROR_INVALID_FORMAT
message = humanize_error(err.message, err)
err_msg = humanize_error(message, err)
elif isinstance(err, Unauthorized):
code = WS_ERROR_UNAUTHORIZED
message = "Unauthorized."
err_msg = "Unauthorized."
else:
# Log unknown errors as exceptions
log_handler = LOGGER.exception
code = WS_ERROR_UNKNOWN_ERROR
message = "Unknown error"
err_msg = "Unknown error"

log_handler("Error handling message. Code: %s, message: %s", code, message)
log_handler("Error handling message. Code: %s, message: %s", code, err_msg)
await self.async_send_message(
error_message(
command_id,
code,
message,
err_msg,
)
)

Expand Down
2 changes: 1 addition & 1 deletion viseron/components/webserver/websocket_api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
LOGGER = logging.getLogger(__name__)


def websocket_command(schema: vol.Schema | dict[str, Any]) -> Callable:
def websocket_command(schema: vol.Schema | dict[Any, Any]) -> Callable:
"""Websocket command decorator."""
command = schema["type"]

Expand Down

0 comments on commit 7d48c90

Please sign in to comment.