Handle wrong WebDAV URL more gracefully in config flow (#141040)

This commit is contained in:
Jan-Philipp Benecke 2025-03-21 11:25:26 +01:00 committed by GitHub
parent 1fafe81d20
commit 4ed2689678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 2 deletions

View File

@ -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"

View File

@ -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": {

View File

@ -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"),
],
)