chore: add authentication type to GitlabAuthenticationError by JohnVillalovos · Pull Request #1793 · python-gitlab/python-gitlab · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gitlab/client.py
19 changes: 18 additions & 1 deletion gitlab/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,24 @@ def __str__(self) -> str:


class GitlabAuthenticationError(GitlabError):
pass
def __init__(
self,
error_message: Union[str, bytes] = "",
response_code: Optional[int] = None,
response_body: Optional[bytes] = None,
auth_type: str = "",
) -> None:
super().__init__(
error_message=error_message,
response_code=response_code,
response_body=response_body,
)
self.auth_type = auth_type
Comment on lines +55 to +67
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add **kwargs to GitlabError and we don't need to reimplement it here? Just pop it from kwargs?


def __str__(self) -> str:
if self.auth_type:
return f"{super().__str__()}: authentication_type: {self.auth_type}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to infer the auth type automatically I'd maybe reformulate this a bit. Not sure exactly how, just authentication_type sounds like it's a variable name defined/passed somewhere. We can maybe check around how more verbose exceptions do it in cpython or some other libraries.

return super().__str__()


class RedirectError(GitlabError):
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_exceptions.py