Use HTTP_BAD_REQUEST constant (#33797)
This commit is contained in:
1 parent
d510384c0d
commit
4c38e6cfa5
24 files changed
+111
-61
No files matched your search
@@ -6,7 +6,12 @@ import os
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.const import CONF_ID, EVENT_COMPONENT_LOADED, HTTP_NOT_FOUND
|
||||
from homeassistant.const import (
|
||||
CONF_ID,
|
||||
EVENT_COMPONENT_LOADED,
|
||||
HTTP_BAD_REQUEST,
|
||||
HTTP_NOT_FOUND,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import ATTR_COMPONENT
|
||||
@@ -129,12 +134,12 @@ class BaseEditConfigView(HomeAssistantView):
|
||||
try:
|
||||
data = await request.json()
|
||||
except ValueError:
|
||||
return self.json_message("Invalid JSON specified", 400)
|
||||
return self.json_message("Invalid JSON specified", HTTP_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
self.key_schema(config_key)
|
||||
except vol.Invalid as err:
|
||||
return self.json_message(f"Key malformed: {err}", 400)
|
||||
return self.json_message(f"Key malformed: {err}", HTTP_BAD_REQUEST)
|
||||
|
||||
hass = request.app["hass"]
|
||||
|
||||
@@ -146,7 +151,7 @@ class BaseEditConfigView(HomeAssistantView):
|
||||
else:
|
||||
self.data_schema(data)
|
||||
except (vol.Invalid, HomeAssistantError) as err:
|
||||
return self.json_message(f"Message malformed: {err}", 400)
|
||||
return self.json_message(f"Message malformed: {err}", HTTP_BAD_REQUEST)
|
||||
|
||||
path = hass.config.path(self.path)
|
||||
|
||||
|
||||
Reference in new issue
Block a user