File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,10 +165,7 @@ import topgg
165165import asyncio
166166import os
167167
168- port = 8080
169- secret = os.getenv(' MY_TOPGG_WEBHOOK_SECRET' )
170-
171- webhooks = topgg.Webhooks(secret, port)
168+ webhooks = topgg.Webhooks(os.getenv(' MY_TOPGG_WEBHOOK_SECRET' ), 8080 )
172169
173170@webhooks.on_vote (' /votes' )
174171def voted (vote : topgg.Vote) -> None :
Original file line number Diff line number Diff line change 2424"""
2525
2626from collections .abc import Awaitable , Callable
27+ from aiohttp import web , ContentTypeError
2728from typing import Any , Optional , Union
29+ from json import JSONDecodeError
2830from inspect import isawaitable
2931from urllib import parse
30- from aiohttp import web
3132
3233
3334RawCallback = Callable [[web .Request ], Awaitable [web .StreamResponse ]]
@@ -134,7 +135,12 @@ async def handler(request: web.Request) -> web.Response:
134135 if request .headers .get ('Authorization' , '' ) != auth :
135136 return web .Response (status = 401 , text = 'Unauthorized' )
136137
137- response = inner_callback (Vote (await request .json ()))
138+ try :
139+ vote = Vote (await request .json ())
140+ except (JSONDecodeError , ContentTypeError ):
141+ return web .Response (status = 400 , text = 'Bad request' )
142+
143+ response = inner_callback (vote )
138144
139145 if isawaitable (response ):
140146 await response
You can’t perform that action at this time.
0 commit comments