mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +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
|
||||
from typing import Any
|
||||
|
||||
from aiowebdav2.exceptions import UnauthorizedError
|
||||
from aiowebdav2.exceptions import MethodNotSupportedError, UnauthorizedError
|
||||
import voluptuous as vol
|
||||
import yarl
|
||||
|
||||
@ -65,6 +65,8 @@ class WebDavConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
result = await client.check()
|
||||
except UnauthorizedError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except MethodNotSupportedError:
|
||||
errors["base"] = "invalid_method"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected error")
|
||||
errors["base"] = "unknown"
|
||||
|
@ -21,6 +21,7 @@
|
||||
"error": {
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"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%]"
|
||||
},
|
||||
"abort": {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from aiowebdav2.exceptions import UnauthorizedError
|
||||
from aiowebdav2.exceptions import MethodNotSupportedError, UnauthorizedError
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
@ -86,6 +86,7 @@ async def test_form_fail(hass: HomeAssistant, webdav_client: AsyncMock) -> None:
|
||||
("exception", "expected_error"),
|
||||
[
|
||||
(UnauthorizedError("https://webdav.demo"), "invalid_auth"),
|
||||
(MethodNotSupportedError("check", "https://webdav.demo"), "invalid_method"),
|
||||
(Exception("Unexpected error"), "unknown"),
|
||||
],
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user