Fix reponse already sent error

This commit is contained in:
Madis Mägi 2023-08-10 20:45:24 +03:00
parent b0d0505000
commit 59bfcfff77

View File

@ -60,11 +60,11 @@ async def view_doorboy_uids(request):
@app.route("/longpoll", stream=True)
async def view_longpoll(request):
response = await request.respond(content_type="text/event-stream")
key = request.headers.get("KEY")
if not key or key not in [DOORBOY_SECRET_FLOOR, DOORBOY_SECRET_WORKSHOP]:
return text("Invalid token")
response = await request.respond(content_type="text/event-stream")
await response.send("data: response-generator-started\n\n")
pipeline = [
{
@ -80,7 +80,9 @@ async def view_longpoll(request):
if event["fullDocument"].get("type") == "open-door":
await response.send("data: %s\n\n" %
event["fullDocument"]["door"])
except pymongo.errors.PyMongoError:
except pymongo.errors.PyMongoError as e:
print(e)
await response.send("data: response-generator-ended\n\n")
return