mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Handle wrong WebDAV URL more gracefully in config flow (#141040)
This commit is contained in:
parent
1fafe81d20
commit
4ed2689678
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiowebdav2.exceptions import UnauthorizedError
|
from aiowebdav2.exceptions import MethodNotSupportedError, UnauthorizedError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import yarl
|
import yarl
|
||||||
|
|
||||||
@ -65,6 +65,8 @@ class WebDavConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
result = await client.check()
|
result = await client.check()
|
||||||
except UnauthorizedError:
|
except UnauthorizedError:
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
|
except MethodNotSupportedError:
|
||||||
|
errors["base"] = "invalid_method"
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Unexpected error")
|
_LOGGER.exception("Unexpected error")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||||
|
"invalid_method": "The server does not support the required methods. Please check whether you have the correct URL. Check with your provider for the correct URL.",
|
||||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from aiowebdav2.exceptions import UnauthorizedError
|
from aiowebdav2.exceptions import MethodNotSupportedError, UnauthorizedError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -86,6 +86,7 @@ async def test_form_fail(hass: HomeAssistant, webdav_client: AsyncMock) -> None:
|
|||||||
("exception", "expected_error"),
|
("exception", "expected_error"),
|
||||||
[
|
[
|
||||||
(UnauthorizedError("https://webdav.demo"), "invalid_auth"),
|
(UnauthorizedError("https://webdav.demo"), "invalid_auth"),
|
||||||
|
(MethodNotSupportedError("check", "https://webdav.demo"), "invalid_method"),
|
||||||
(Exception("Unexpected error"), "unknown"),
|
(Exception("Unexpected error"), "unknown"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user