app: catch starlette.HTTPException in SPA fallback
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
StaticFiles is a Starlette primitive — its 404 raises starlette.exceptions.HTTPException, NOT fastapi.HTTPException (which subclasses Starlette's). My initial except clause caught the subclass and let the base class propagate, so /scenarios still 404'd. Switch to except StarletteHTTPException so both the parent and any FastAPI subclass are caught. Verified end-to-end via chrome-service in the next deploy. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
d91473a018
commit
472acd5804
1 changed files with 2 additions and 2 deletions
|
|
@ -33,11 +33,11 @@ from pathlib import Path
|
|||
from typing import Any
|
||||
|
||||
from fastapi import Depends, FastAPI, status
|
||||
from fastapi.exceptions import HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
||||
from starlette.types import Scope
|
||||
|
||||
from fire_planner.api.auth import require_bearer
|
||||
|
|
@ -159,7 +159,7 @@ class _SPAStaticFiles(StaticFiles):
|
|||
async def get_response(self, path: str, scope: Scope): # type: ignore[no-untyped-def]
|
||||
try:
|
||||
return await super().get_response(path, scope)
|
||||
except HTTPException as exc:
|
||||
except StarletteHTTPException as exc:
|
||||
if exc.status_code == 404:
|
||||
index = Path(self.directory) / "index.html" # type: ignore[arg-type]
|
||||
if index.is_file():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue