-
In aiohttp server code, is there a mechanism to programmatically capture connection errors (e.g., SSLError)? For example, my server requires a client to have certificates. When a client attempts to connect without a certificate, from an aiohttp perspective, I see nothing. If I turn on asyncio debugging (PYTHONASYNCIODEBUG=1), I see an SSLError printed: I've looked at the documentation for middleware and signals, but they appear to be focused on issues that occur at an HTTP layer. Is there a way to catch these sorts of errors so that custom handling could be done? I'd like to be able to take some specific actions when certain types of connection errors occur. Thanks! And my apologies in advance if this is well-documented and I missed it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Maybe if there's a traceback with that SSLError, it could provide a hint on where to look, but I'm not sure what's available, and it might be that the error is in the asyncio server code and not accessible.. But, typically, this would all be handled with nginx or similar, rather than in application code. We don't generally recommend exposing the application directly for a production environment. |
Beta Was this translation helpful? Give feedback.
-
I do not know the aiohttp opinion on using set_exception_handler, but I was able to capture the exceptions with it provided I enabled debugging. I have no idea why enabling debugging was necessary. Here's a simple example:
You can, of course, replace the lambda with your own function to handle the exceptions as you like. |
Beta Was this translation helpful? Give feedback.
I do not know the aiohttp opinion on using set_exception_handler, but I was able to capture the exceptions with it provided I enabled debugging. I have no idea why enabling debugging was necessary.
Here's a simple example:
You can, of course, replace the lambda with your own function to handle the exceptions as you like.