botbuilder-python icon indicating copy to clipboard operation
botbuilder-python copied to clipboard

Treat HTTPException as it is, necessary to keep the original status code

Open takeshi-yashiro opened this issue 3 years ago • 0 comments

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 avatar May 17 '22 10:05 takeshi-yashiro