Neoteroi / BlackSheep

Fast ASGI web framework for Python
https://www.neoteroi.dev/blacksheep/
MIT License
1.86k stars 78 forks source link

Custom HTTPException should support specific error handlers by type #342

Closed RobertoPrevato closed 1 year ago

RobertoPrevato commented 1 year ago

Custom HTTPException currently support specific exception handlers only by their HTTP status code. It is best supporting specific exception handlers by type, and give them precedence.

That is, in baseapp.pyx:

    cdef object get_http_exception_handler(self, HTTPException http_exception):
        try:
            return self.exceptions_handlers[type(http_exception)]
        except KeyError:
            return self.exceptions_handlers.get(http_exception.status, common_http_exception_handler)