mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 20:40:18 +00:00
Use HTTPStatus instead of HTTP_ consts and magic values in comp.../[bc]* (#57989)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""The HTTP api to control the cloud integration."""
|
||||
import asyncio
|
||||
from functools import wraps
|
||||
from http import HTTPStatus
|
||||
import logging
|
||||
|
||||
import aiohttp
|
||||
@@ -20,12 +21,6 @@ from homeassistant.components.google_assistant import helpers as google_helpers
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.components.websocket_api import const as ws_const
|
||||
from homeassistant.const import (
|
||||
HTTP_BAD_GATEWAY,
|
||||
HTTP_BAD_REQUEST,
|
||||
HTTP_INTERNAL_SERVER_ERROR,
|
||||
HTTP_UNAUTHORIZED,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
@@ -48,19 +43,19 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_CLOUD_ERRORS = {
|
||||
InvalidTrustedNetworks: (
|
||||
HTTP_INTERNAL_SERVER_ERROR,
|
||||
HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
"Remote UI not compatible with 127.0.0.1/::1 as a trusted network.",
|
||||
),
|
||||
InvalidTrustedProxies: (
|
||||
HTTP_INTERNAL_SERVER_ERROR,
|
||||
HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
"Remote UI not compatible with 127.0.0.1/::1 as trusted proxies.",
|
||||
),
|
||||
asyncio.TimeoutError: (
|
||||
HTTP_BAD_GATEWAY,
|
||||
HTTPStatus.BAD_GATEWAY,
|
||||
"Unable to reach the Home Assistant cloud.",
|
||||
),
|
||||
aiohttp.ClientError: (
|
||||
HTTP_INTERNAL_SERVER_ERROR,
|
||||
HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
"Error making internal request",
|
||||
),
|
||||
}
|
||||
@@ -96,15 +91,15 @@ async def async_setup(hass):
|
||||
|
||||
_CLOUD_ERRORS.update(
|
||||
{
|
||||
auth.UserNotFound: (HTTP_BAD_REQUEST, "User does not exist."),
|
||||
auth.UserNotConfirmed: (HTTP_BAD_REQUEST, "Email not confirmed."),
|
||||
auth.UserNotFound: (HTTPStatus.BAD_REQUEST, "User does not exist."),
|
||||
auth.UserNotConfirmed: (HTTPStatus.BAD_REQUEST, "Email not confirmed."),
|
||||
auth.UserExists: (
|
||||
HTTP_BAD_REQUEST,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"An account with the given email already exists.",
|
||||
),
|
||||
auth.Unauthenticated: (HTTP_UNAUTHORIZED, "Authentication failed."),
|
||||
auth.Unauthenticated: (HTTPStatus.UNAUTHORIZED, "Authentication failed."),
|
||||
auth.PasswordChangeRequired: (
|
||||
HTTP_BAD_REQUEST,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"Password change required.",
|
||||
),
|
||||
}
|
||||
@@ -157,7 +152,7 @@ def _process_cloud_exception(exc, where):
|
||||
|
||||
if err_info is None:
|
||||
_LOGGER.exception("Unexpected error processing request for %s", where)
|
||||
err_info = (HTTP_BAD_GATEWAY, f"Unexpected error: {exc}")
|
||||
err_info = (HTTPStatus.BAD_GATEWAY, f"Unexpected error: {exc}")
|
||||
|
||||
return err_info
|
||||
|
||||
|
||||
Reference in New Issue
Block a user