ci
This commit is contained in:
parent
fc85ab2ef7
commit
0ccb23328e
1 changed files with 16 additions and 5 deletions
|
|
@ -46,17 +46,28 @@ requests.models.complexjson.dumps = functools.partial(json.dumps, cls=CustomJSON
|
||||||
|
|
||||||
async def _coerce_request_data() -> dict:
|
async def _coerce_request_data() -> dict:
|
||||||
"""Fetch JSON body with sane defaults; fallback to form data."""
|
"""Fetch JSON body with sane defaults; fallback to form data."""
|
||||||
|
payload = None
|
||||||
|
last_error: Exception | None = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = await request.get_json(force=True, silent=True)
|
payload = await request.get_json(force=True, silent=True)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
last_error = e
|
||||||
payload = None
|
payload = None
|
||||||
|
|
||||||
if payload is None:
|
if payload is None:
|
||||||
try:
|
try:
|
||||||
payload = (await request.form).to_dict()
|
form = await request.form
|
||||||
except Exception:
|
payload = form.to_dict()
|
||||||
payload = {}
|
except Exception as e:
|
||||||
return payload or {}
|
last_error = e
|
||||||
|
|
||||||
|
if payload is None:
|
||||||
|
if last_error is not None:
|
||||||
|
raise last_error
|
||||||
|
raise ValueError("No JSON body or form data found in request.")
|
||||||
|
|
||||||
|
return payload or {}
|
||||||
|
|
||||||
async def get_request_json():
|
async def get_request_json():
|
||||||
return await _coerce_request_data()
|
return await _coerce_request_data()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue