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

Create new exception type for authentication errors #202

Open
tim-schilling opened this issue Jan 18, 2022 · 0 comments
Open

Create new exception type for authentication errors #202

tim-schilling opened this issue Jan 18, 2022 · 0 comments

Comments

@tim-schilling
Copy link

Currently the library raises an exception for authentication failures. I think it should be a specific exception class so it can be filtered out more easily.

In my case, I'm overriding strawberry's schema to support an ignoreable collection of exceptions. These won't be passed to the logger and thus avoid the exception handling logic. However, strawberry-django-jwt uses an exception class that's subclassed when a user enters the wrong credentials.

class Schema(strawberry.Schema):
    ignored_errors: tuple[Type[Exception]]

    def __init__(self, *args, ignored_errors=None, **kwargs):
        super().__init__(*args, **kwargs)
        self.ignored_errors = ignored_errors

    def process_errors(
        self,
        errors: List[GraphQLError],
        execution_context: Optional[ExecutionContext] = None,
    ) -> None:
        for error in errors:
            if error.original_error and self.ignored_errors and isinstance(
                error.original_error, self.ignored_errors
            ):
                continue
            StrawberryLogger.error(error, execution_context)

If it seems reasonable, I can create the PR.

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

1 participant