Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

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

Merged
tracyboehrer (tracyboehrer) merged 5 commits into
microsoft:mainfrom
takeshi-yashiro:fix-all-http-errors-treated-as-500
Jan 26, 2024
Merged

tracyboehrer (tracyboehrer) merged 5 commits into
microsoft:mainfrom
takeshi-yashiro:fix-all-http-errors-treated-as-500

Conversation

@takeshi-yashiro

@takeshi-yashiro Takeshi YASHIRO (takeshi-yashiro) commented May 17, 2022 •

Copy link
Copy Markdown
Contributor

#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

@tracyboehrer 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 (tracyboehrer) merged commit d6b5e67 into microsoft:main Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants