Skip to content

Commit

Permalink
fix: propagate SetupError in setup flow
Browse files Browse the repository at this point in the history
Propagate error_type if the integration driver returns a SetupError during the setup flow.
  • Loading branch information
zehnm committed Nov 5, 2023
1 parent 52cd2c6 commit f890ebb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ucapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ async def _setup_driver(

await self.acknowledge_command(websocket, req_id)

result = False
try:
action = await self._setup_handler(
uc.DriverSetupRequest(msg_data["setup_data"])
Expand All @@ -503,23 +504,26 @@ async def _setup_driver(
await self.request_driver_setup_user_input(
websocket, action.title, action.settings
)
return True
result = True
if isinstance(action, uc.RequestUserConfirmation):
await self.driver_setup_progress(websocket)
await self.request_driver_setup_user_confirmation(
websocket, action.title, action.header, action.image, action.footer
)
return True
result = True
if isinstance(action, uc.SetupComplete):
await self.driver_setup_complete(websocket)
return True
result = True
if isinstance(action, uc.SetupError):
await self.driver_setup_error(websocket, action.error_type)
result = True

# error action is left, handled below
# TODO define custom exceptions?
except Exception as ex: # pylint: disable=W0718
_LOG.error("Exception in setup handler, aborting setup! Exception: %s", ex)

return False
return result

async def _set_driver_user_data(
self, websocket, req_id: int, msg_data: dict[str, Any] | None
Expand Down

0 comments on commit f890ebb

Please sign in to comment.