nanobot-voice-interface/route_helpers.py

16 lines
433 B
Python
Raw Permalink Normal View History

from __future__ import annotations
import json
from fastapi import Request
async def read_json_request(request: Request) -> dict:
try:
payload = await request.json()
except (json.JSONDecodeError, UnicodeDecodeError) as exc:
raise ValueError("request body must be valid JSON") from exc
if not isinstance(payload, dict):
raise ValueError("request body must be a JSON object")
return payload