Feature: Enhance error handling and logging #103

Closed
opened 2026-06-04 10:17:04 +02:00 by JTHesse · 4 comments

Currently, I see many Timeout Errors which I would like to further analyze. To do that it would be beneficial to catch ollama errors and log further information, for example the endpoint and model used:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/site-packages/uvicorn/protocols/http/h11_impl.py", line 415, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self.scope, self.receive, self.send
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.14/site-packages/uvicorn/middleware/proxy_headers.py", line 56, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/fastapi/applications.py", line 1159, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/applications.py", line 90, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.14/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.14/site-packages/starlette/middleware/base.py", line 198, in __call__
    raise app_exc
  File "/usr/local/lib/python3.14/site-packages/starlette/middleware/base.py", line 144, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/usr/local/lib/python3.14/site-packages/starlette/middleware/cors.py", line 88, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.14/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/routing.py", line 660, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/routing.py", line 680, in app
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/fastapi/routing.py", line 134, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.14/site-packages/fastapi/routing.py", line 121, in app
    await response(scope, receive, send)
  File "/usr/local/lib/python3.14/site-packages/starlette/responses.py", line 273, in __call__
    with collapse_excgroups():
         ~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/starlette/_utils.py", line 87, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.14/site-packages/starlette/responses.py", line 277, in wrap
    await func()
  File "/usr/local/lib/python3.14/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
    ...<2 lines>...
        await send({"type": "http.response.body", "body": chunk, "more_body": True})
  File "/app/router.py", line 2346, in stream_chat_response
    async for chunk in _async_gen:
    ...<57 lines>...
        yield json_line.encode("utf-8") + b"\n"
  File "/usr/local/lib/python3.14/site-packages/ollama/_client.py", line 782, in inner
    raise ResponseError(e.response.text, e.response.status_code) from None
ollama._types.ResponseError: <html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>
 (status code: 504)
Currently, I see many Timeout Errors which I would like to further analyze. To do that it would be beneficial to catch ollama errors and log further information, for example the endpoint and model used: ``` ERROR: Exception in ASGI application Traceback (most recent call last): File "/usr/local/lib/python3.14/site-packages/uvicorn/protocols/http/h11_impl.py", line 415, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ self.scope, self.receive, self.send ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/local/lib/python3.14/site-packages/uvicorn/middleware/proxy_headers.py", line 56, in __call__ return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.14/site-packages/fastapi/applications.py", line 1159, in __call__ await super().__call__(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/applications.py", line 90, in __call__ await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/middleware/errors.py", line 186, in __call__ raise exc File "/usr/local/lib/python3.14/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/usr/local/lib/python3.14/site-packages/starlette/middleware/base.py", line 198, in __call__ raise app_exc File "/usr/local/lib/python3.14/site-packages/starlette/middleware/base.py", line 144, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/usr/local/lib/python3.14/site-packages/starlette/middleware/cors.py", line 88, in __call__ await self.app(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/middleware/exceptions.py", line 63, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/usr/local/lib/python3.14/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__ await self.app(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/routing.py", line 660, in __call__ await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/routing.py", line 680, in app await route.handle(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/fastapi/routing.py", line 134, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/usr/local/lib/python3.14/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/usr/local/lib/python3.14/site-packages/fastapi/routing.py", line 121, in app await response(scope, receive, send) File "/usr/local/lib/python3.14/site-packages/starlette/responses.py", line 273, in __call__ with collapse_excgroups(): ~~~~~~~~~~~~~~~~~~^^ File "/usr/local/lib/python3.14/contextlib.py", line 162, in __exit__ self.gen.throw(value) ~~~~~~~~~~~~~~^^^^^^^ File "/usr/local/lib/python3.14/site-packages/starlette/_utils.py", line 87, in collapse_excgroups raise exc File "/usr/local/lib/python3.14/site-packages/starlette/responses.py", line 277, in wrap await func() File "/usr/local/lib/python3.14/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: ...<2 lines>... await send({"type": "http.response.body", "body": chunk, "more_body": True}) File "/app/router.py", line 2346, in stream_chat_response async for chunk in _async_gen: ...<57 lines>... yield json_line.encode("utf-8") + b"\n" File "/usr/local/lib/python3.14/site-packages/ollama/_client.py", line 782, in inner raise ResponseError(e.response.text, e.response.status_code) from None ollama._types.ResponseError: <html> <head><title>504 Gateway Time-out</title></head> <body> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html> (status code: 504) ```
alpha-nerd self-assigned this 2026-06-04 10:21:24 +02:00
alpha-nerd added the
enhancement
label 2026-06-04 10:30:36 +02:00
alpha-nerd added reference dev-0.9.x-ref 2026-06-04 10:30:54 +02:00
Owner

This commit d3b2ee3047 in dev should do the trick.

This commit d3b2ee3047 in dev should do the trick.
Author

Amazing, thank you!

Amazing, thank you!
Owner

docker pull bitfreedom.net/nomyo-ai/nomyo-router:0.9.9-rc2
contains it already

docker pull bitfreedom.net/nomyo-ai/nomyo-router:0.9.9-rc2 contains it already
Author

Works great!

Works great!
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: nomyo-ai/nomyo-router#103
No description provided.