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

fix: Treat HTTPException as it is, necessary to keep the original status code #1939

Merged

Conversation

takeshi-yashiro
Copy link
Contributor

@takeshi-yashiro takeshi-yashiro commented May 17, 2022

#minor

Fixes aiohttp_channel_service_exception_middleware.py changing all HTTP errors turned into 500

Description

This patch fixes aiohttp_channel_service_exception_middleware.py changing all HTTP errors into 500, so that applications can return any other status values, like 400.

The current implementation of aiohttp_channel_service_exception_middleware.py catches all exceptions and raises HTTPInternalServerError instead of the original exception. As this applies to aiohttp.web.HTTPException based exceptions, this prevents application code to status errors other than 500. For example, the following route results in 500 error instead of 400.

from aiohttp import web

async def badreq(request):
    return web.Response(text="BADREQ", status=400)

Specific Changes

In order to avoid this, this patch catches HTTPException and throws as it is. The following two lines are added:

    except HTTPException:
        raise

@takeshi-yashiro takeshi-yashiro requested a review from a team as a code owner May 17, 2022 10:32
@tracyboehrer tracyboehrer changed the title Treat HTTPException as it is, necessary to keep the original status code fix: Treat HTTPException as it is, necessary to keep the original status code Nov 29, 2023
@tracyboehrer tracyboehrer merged commit d6b5e67 into microsoft:main Jan 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants