From a221d7b35bc20da758e7467fe789e16613c54275 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Fri, 24 Aug 2018 17:09:55 +0200 Subject: Raise an exception on https redirects for PUT/POST POST and PUT requests are modified by clients when redirections happen. A common problem with python-gitlab is a misconfiguration of the server URL: the http to https redirection breaks some requests. With this change python-gitlab should detect problematic redirections, and raise a proper exception instead of failing with a cryptic error. Closes #565 --- gitlab/exceptions.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gitlab/exceptions.py') diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 6736f67..650328a 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -41,6 +41,10 @@ class GitlabAuthenticationError(GitlabError): pass +class RedirectError(GitlabError): + pass + + class GitlabParsingError(GitlabError): pass -- cgit v1.2.1 From 1fb1296c9191e57e109c4e5eb9504bce191a6ff1 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 24 Nov 2018 17:37:10 +0100 Subject: Improve error message handling in exceptions * Depending on the request Gitlab has a 'message' or 'error' attribute in the json data, handle both * Add some consistency by converting messages to unicode or str for exceptions (depending on the python version) Closes #616 --- gitlab/exceptions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gitlab/exceptions.py') diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 650328a..0822d3e 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -28,7 +28,12 @@ class GitlabError(Exception): # Full http response self.response_body = response_body # Parsed error message from gitlab - self.error_message = error_message + try: + # if we receive str/bytes we try to convert to unicode/str to have + # consistent message types (see #616) + self.error_message = error_message.decode() + except Exception: + self.error_message = error_message def __str__(self): if self.response_code is not None: -- cgit v1.2.1