Make body optional
This commit is contained in:
parent
e16fea8999
commit
d14cf22f33
1 changed files with 3 additions and 1 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue