Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cathing internal exceptions #9882

Closed
1 task done
daniel-kukiela opened this issue Nov 14, 2024 · 1 comment
Closed
1 task done

Cathing internal exceptions #9882

daniel-kukiela opened this issue Nov 14, 2024 · 1 comment
Labels

Comments

@daniel-kukiela
Copy link

daniel-kukiela commented Nov 14, 2024

Describe the bug

How can I catch errors like this while using aiohttp.web.Application():

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 332, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadHttpMessage: 400, message:
  Invalid header value char:
  [...]

The client-side receives HTTP 400 with the exception text which I want to avoid (and also log the exception using my logger). It does not seem like I can catch it using middleware or override in any way which I would possibly call a bug (unless I'm missing something obvious)

It seems like this is where this unwanted response for the client is being created: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_protocol.py#L411

To Reproduce

  1. Create an Application
  2. Run the server
  3. Send the request with invalid headers

Expected behavior

A way to catch and handle the error in my app to log it and send back a generic error message

Logs/tracebacks

None

Python Version

$ python --version
3.11

aiohttp Version

$ python -m pip show aiohttp
3.8.5

multidict Version

$ python -m pip show multidict
6.0.4

propcache Version

$ python -m pip show propcache
Not installed

yarl Version

$ python -m pip show yarl
1.9.2

OS

Ubuntu 22.04 LTS

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@Dreamsorcerer
Copy link
Member

#3287

Feel free to look at making a PR.

@Dreamsorcerer Dreamsorcerer closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants