Make body optional

This commit is contained in:
Paulus Schoutsen 2018-09-24 20:18:49 +02:00
parent e16fea8999
commit d14cf22f33

View file

@ -3,6 +3,7 @@
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/webhook/ https://home-assistant.io/components/webhook/
""" """
import json
import logging import logging
from aiohttp.web import Response from aiohttp.web import Response
@ -75,8 +76,9 @@ class WebhookView(HomeAssistantView):
'Received message for unregistered webhook %s', webhook_id) 'Received message for unregistered webhook %s', webhook_id)
return Response(status=200) return Response(status=200)
body = await request.text()
try: try:
data = await request.json() data = json.load(body) if body else {}
except ValueError: except ValueError:
_LOGGER.warning( _LOGGER.warning(
'Received webhook %s with invalid JSON', webhook_id) 'Received webhook %s with invalid JSON', webhook_id)