mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Catch timeout errors in Steam config flow (#175052)
This commit is contained in:
@@ -65,12 +65,14 @@ class SteamFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
name = str(res["personaname"])
|
||||
else:
|
||||
errors["base"] = "invalid_account"
|
||||
except steam.api.HTTPTimeoutError:
|
||||
errors["base"] = "timeout_connect"
|
||||
except steam.api.HTTPError as ex:
|
||||
errors["base"] = (
|
||||
"invalid_auth" if "403" in str(ex) else "cannot_connect"
|
||||
)
|
||||
except Exception as ex: # noqa: BLE001
|
||||
LOGGER.exception("Unknown exception: %s", ex)
|
||||
except Exception: # noqa: BLE001
|
||||
LOGGER.exception("Unknown exception")
|
||||
errors["base"] = "unknown"
|
||||
if not errors:
|
||||
return self.async_create_entry(
|
||||
@@ -107,12 +109,14 @@ class SteamFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
validate_input, {**entry.data, **user_input}
|
||||
):
|
||||
errors["base"] = "invalid_account"
|
||||
except steam.api.HTTPTimeoutError:
|
||||
errors["base"] = "timeout_connect"
|
||||
except steam.api.HTTPError as ex:
|
||||
errors["base"] = (
|
||||
"invalid_auth" if "403" in str(ex) else "cannot_connect"
|
||||
)
|
||||
except Exception as ex: # noqa: BLE001
|
||||
LOGGER.exception("Unknown exception: %s", ex)
|
||||
except Exception: # noqa: BLE001
|
||||
LOGGER.exception("Unknown exception")
|
||||
errors["base"] = "unknown"
|
||||
|
||||
if not errors:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_account": "Invalid Steam ID",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"timeout_connect": "[%key:common::config_flow::error::timeout_connect%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
},
|
||||
"step": {
|
||||
|
||||
@@ -54,7 +54,7 @@ async def test_flow_user(
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "error_msg"),
|
||||
[
|
||||
(steam.api.HTTPTimeoutError, "cannot_connect"),
|
||||
(steam.api.HTTPTimeoutError, "timeout_connect"),
|
||||
(steam.api.HTTPError, "cannot_connect"),
|
||||
(steam.api.HTTPError("403"), "invalid_auth"),
|
||||
(ValueError, "unknown"),
|
||||
@@ -146,7 +146,7 @@ async def test_flow_reauth(
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "error_msg"),
|
||||
[
|
||||
(steam.api.HTTPTimeoutError, "cannot_connect"),
|
||||
(steam.api.HTTPTimeoutError, "timeout_connect"),
|
||||
(steam.api.HTTPError, "cannot_connect"),
|
||||
(steam.api.HTTPError("403"), "invalid_auth"),
|
||||
(ValueError, "unknown"),
|
||||
|
||||
Reference in New Issue
Block a user