Skip to content

Commit

Permalink
display unexpected exception type in config window
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-or committed Jul 6, 2024
1 parent f8eed36 commit 6e78861
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions custom_components/hikvision_next/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo
except ConnectTimeout:
errors["base"] = "cannot_connect"
except Exception as ex: # pylint: disable=broad-except
_LOGGER.error("Unexpected exception %s", ex)
errors["base"] = f"Unexpected exception: {ex}"
_LOGGER.error("Unexpected %s %s", {type(ex).__name__}, ex)
errors["base"] = f"Unexpected {type(ex).__name__}: {ex}"
else:
return self.async_create_entry(title=isapi.device_info.name, data=user_input)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_wrong_credentials_config_flow(hass, mock_isapi):
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"

respx.get(f'{TEST_HOST}/ISAPI/System/deviceInfo').respond(status_code=401)
respx.get(f"{TEST_HOST}/ISAPI/System/deviceInfo").respond(status_code=401)
result = await hass.config_entries.flow.async_configure(result["flow_id"], user_input=TEST_CONFIG)
assert result.get("type") == FlowResultType.FORM
assert result.get("errors") == {"base": "invalid_auth"}
Expand All @@ -72,4 +72,4 @@ async def test_unexpeced_exception_config_flowget_device_info_mock(get_device_in
get_device_info_mock.side_effect = Exception("Something went wrong")
result = await hass.config_entries.flow.async_configure(result["flow_id"], user_input=TEST_CONFIG)
assert result.get("type") == FlowResultType.FORM
assert result.get("errors") == {"base": "Unexpected exception: Something went wrong"}
assert result.get("errors") == {"base": "Unexpected Exception: Something went wrong"}

0 comments on commit 6e78861

Please sign in to comment.