Fix API crash: status_code=204 with response body assertion error
FastAPI rejects status_code=204 on routes with a return type annotation. Return an explicit Response(status_code=204) instead.
This commit is contained in:
parent
7dc8dc736f
commit
9b3d35669f
1 changed files with 5 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
"""Frontend performance metrics ingestion endpoint."""
|
"""Frontend performance metrics ingestion endpoint."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter, Response
|
||||||
from pydantic import BaseModel, Field, field_validator
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
|
||||||
import api.metrics as app_metrics
|
import api.metrics as app_metrics
|
||||||
|
|
@ -26,8 +26,8 @@ class PerfSample(BaseModel):
|
||||||
perf_router = APIRouter(tags=["perf"])
|
perf_router = APIRouter(tags=["perf"])
|
||||||
|
|
||||||
|
|
||||||
@perf_router.post("/api/perf", status_code=204)
|
@perf_router.post("/api/perf")
|
||||||
async def record_perf(samples: list[PerfSample]) -> None:
|
async def record_perf(samples: list[PerfSample]) -> Response:
|
||||||
if len(samples) > MAX_BATCH_SIZE:
|
if len(samples) > MAX_BATCH_SIZE:
|
||||||
samples = samples[:MAX_BATCH_SIZE]
|
samples = samples[:MAX_BATCH_SIZE]
|
||||||
|
|
||||||
|
|
@ -41,3 +41,5 @@ async def record_perf(samples: list[PerfSample]) -> None:
|
||||||
app_metrics.frontend_main_thread.record(s.value, attrs)
|
app_metrics.frontend_main_thread.record(s.value, attrs)
|
||||||
elif s.metric == "feature_count":
|
elif s.metric == "feature_count":
|
||||||
app_metrics.frontend_feature_count.record(s.value)
|
app_metrics.frontend_feature_count.record(s.value)
|
||||||
|
|
||||||
|
return Response(status_code=204)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue