Files
calminer/middleware/validation.py
zwitschi 5ecd2b8d19 feat: Add main CSS styles for the application
feat: Refactor Dashboard template to extend base layout and improve structure

feat: Enhance Parameter Input template with improved layout and feedback mechanisms

feat: Update Scenario Form template to utilize base layout and improve user experience

feat: Create base layout template for consistent styling across pages

feat: Add Consumption, Costs, Equipment, Maintenance, Production, Reporting, and Simulations templates with placeholders for future functionality

feat: Implement base header and footer partials for consistent navigation and footer across the application
2025-10-20 22:58:59 +02:00

17 lines
597 B
Python

from typing import Awaitable, Callable
from fastapi import HTTPException, Request, Response
MiddlewareCallNext = Callable[[Request], Awaitable[Response]]
async def validate_json(request: Request, call_next: MiddlewareCallNext) -> Response:
# Only validate JSON for requests with a body
if request.method in ("POST", "PUT", "PATCH"):
try:
# attempt to parse json body
await request.json()
except Exception:
raise HTTPException(status_code=400, detail="Invalid JSON payload")
response = await call_next(request)
return response