mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 06:46:14 +00:00
Narrow WSGI fallback to only catch call signature TypeErrors
The bare except TypeError when calling mounted apps would silently swallow any TypeError raised inside an ASGI app and incorrectly convert it to WSGI mode. Now only falls back when the error is about call arguments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+15
-6
@@ -459,13 +459,22 @@ class Router:
|
||||
if path.startswith(path_prefix):
|
||||
scope["path"] = path[len(path_prefix) :] or "/"
|
||||
scope["root_path"] = root_path + path_prefix
|
||||
try:
|
||||
await app(scope, receive, send)
|
||||
return
|
||||
except TypeError:
|
||||
from a2wsgi import WSGIMiddleware
|
||||
|
||||
app = WSGIMiddleware(app)
|
||||
if not (inspect.iscoroutinefunction(app) or hasattr(app, "__asgi_app__")):
|
||||
# Check if it looks like a WSGI app (callable with fewer params)
|
||||
try:
|
||||
await app(scope, receive, send)
|
||||
return
|
||||
except TypeError as exc:
|
||||
# Only fall back to WSGI if the error is about call signature
|
||||
if "argument" not in str(exc) and "positional" not in str(exc):
|
||||
raise
|
||||
from a2wsgi import WSGIMiddleware
|
||||
|
||||
app = WSGIMiddleware(app)
|
||||
await app(scope, receive, send)
|
||||
return
|
||||
else:
|
||||
await app(scope, receive, send)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user