Kludex / asgi-logger

Access logger for ASGI servers! :tada:
MIT License
48 stars 8 forks source link

The middleware produces "KeyError: 'status'" sometimes. #42

Open alex-kowalczyk opened 1 year ago

alex-kowalczyk commented 1 year ago

The full stack below.

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/app/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/starlette_context/middleware/raw_middleware.py", line 92, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 83, in __call__
    await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "/app/.venv/lib/python3.11/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/app/.venv/lib/python3.11/site-packages/asgi_logger/middleware.py", line 64, in __call__
    self.log(scope, info)
  File "/app/.venv/lib/python3.11/site-packages/asgi_logger/middleware.py", line 67, in log
    self.logger.info(self.format, AccessLogAtoms(scope, info))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/asgi_logger/middleware.py", line 81, in __init__
    status = info["response"]["status"]
             ~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'status'