mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Json api fix (#10017)
* Dont let json parsing errors result in a 500 * Fixed error description
This commit is contained in:
parent
796a3ff49d
commit
9f62d5e3cf
@ -262,7 +262,11 @@ class APIEventView(HomeAssistantView):
|
|||||||
def post(self, request, event_type):
|
def post(self, request, event_type):
|
||||||
"""Fire events."""
|
"""Fire events."""
|
||||||
body = yield from request.text()
|
body = yield from request.text()
|
||||||
|
try:
|
||||||
event_data = json.loads(body) if body else None
|
event_data = json.loads(body) if body else None
|
||||||
|
except ValueError:
|
||||||
|
return self.json_message('Event data should be valid JSON',
|
||||||
|
HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
if event_data is not None and not isinstance(event_data, dict):
|
if event_data is not None and not isinstance(event_data, dict):
|
||||||
return self.json_message('Event data should be a JSON object',
|
return self.json_message('Event data should be a JSON object',
|
||||||
@ -309,7 +313,11 @@ class APIDomainServicesView(HomeAssistantView):
|
|||||||
"""
|
"""
|
||||||
hass = request.app['hass']
|
hass = request.app['hass']
|
||||||
body = yield from request.text()
|
body = yield from request.text()
|
||||||
|
try:
|
||||||
data = json.loads(body) if body else None
|
data = json.loads(body) if body else None
|
||||||
|
except ValueError:
|
||||||
|
return self.json_message('Data should be valid JSON',
|
||||||
|
HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
with AsyncTrackStates(hass) as changed_states:
|
with AsyncTrackStates(hass) as changed_states:
|
||||||
yield from hass.services.async_call(domain, service, data, True)
|
yield from hass.services.async_call(domain, service, data, True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user