Open Midnighter opened 2 years ago
Hi,
At the moment, there is the base error class
class AuthJWTException(Exception): """ Base except which all fastapi_jwt_auth errors extend """ pass
and then all the others inherit from that and add the two attributes status_code and message. In the docs, you suggest the following handler:
status_code
message
@app.exception_handler(AuthJWTException) def authjwt_exception_handler(request: Request, exc: AuthJWTException): return JSONResponse( status_code=exc.status_code, content={"detail": exc.message} )
which uses the error's attributes. Technically, the annotated type does not have these attributes.
I don't know why you chose this design but I would like to make a PR to change it to:
class AuthJWTException(Exception): """ Base exception which all fastapi_jwt_auth errors extend. """ def __init__(self,status_code: int, message: str, **kwargs): super().__init__(**kwargs) self.status_code = status_code self.message = message
and then change all others to the following init:
def __init__(self,status_code: int, message: str, **kwargs): super().__init__(status_code=status_code, message=message, **kwargs)
same problem, any updates on this ?
Hi,
At the moment, there is the base error class
and then all the others inherit from that and add the two attributes
status_code
andmessage
. In the docs, you suggest the following handler:which uses the error's attributes. Technically, the annotated type does not have these attributes.
I don't know why you chose this design but I would like to make a PR to change it to:
and then change all others to the following init: