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

Error hierarchy #81

Open
Midnighter opened this issue Mar 28, 2022 · 1 comment
Open

Error hierarchy #81

Midnighter opened this issue Mar 28, 2022 · 1 comment

Comments

@Midnighter
Copy link

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:

@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)
@SergeyKapshuchenko
Copy link

same problem, any updates on this ?

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

No branches or pull requests

2 participants