Skip to content

Create new exception type for authentication errors #202

@tim-schilling

Description

@tim-schilling

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions