Avoid unknown error translation strings in anthropic (#127823)

This commit is contained in:
epenet 2024-10-08 15:59:45 +02:00 committed by GitHub
parent 4d003f51c3
commit d8b51b4f2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -87,10 +87,13 @@ class AnthropicConfigFlow(ConfigFlow, domain=DOMAIN):
except anthropic.APIConnectionError:
errors["base"] = "cannot_connect"
except anthropic.APIStatusError as e:
if isinstance(e.body, dict):
errors["base"] = e.body.get("error", {}).get("type", "unknown")
else:
errors["base"] = "unknown"
errors["base"] = "unknown"
if (
isinstance(e.body, dict)
and (error := e.body.get("error"))
and error.get("type") == "authentication_error"
):
errors["base"] = "authentication_error"
except Exception:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"

View File

@ -108,7 +108,7 @@ async def test_options(
),
body={"type": "error", "error": {"type": "invalid_request_error"}},
),
"invalid_request_error",
"unknown",
),
(
AuthenticationError(