diff --git a/src/titiler/core/titiler/core/utils.py b/src/titiler/core/titiler/core/utils.py index 0f7310ef8..61225e819 100644 --- a/src/titiler/core/titiler/core/utils.py +++ b/src/titiler/core/titiler/core/utils.py @@ -313,9 +313,15 @@ def update_openapi(app: FastAPI) -> FastAPI: SOFTWARE. """ # Find the route for the openapi_url in the app - openapi_route: Route = next( - route for route in app.router.routes if route.path == app.openapi_url - ) + openapi_route: Route | None = None + for route in app.router.routes: + if route.path == app.openapi_url: + openapi_route = route + break + + if openapi_route is None: + raise StopIteration() + # Store the old endpoint function so we can call it from the patched function old_endpoint = openapi_route.endpoint @@ -335,7 +341,6 @@ async def patched_openapi_endpoint(req: Request) -> Response: # our patched function and replace the existing app with it. openapi_route.app = request_response(patched_openapi_endpoint) - # return the patched app return app