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/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gitlab/__init__.py') diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 99ff5c5..477d564 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -490,10 +490,14 @@ class Gitlab(object): time.sleep(wait_time) continue + error_message = result.content try: - error_message = result.json()['message'] + error_json = result.json() + for k in ('message', 'error'): + if k in error_json: + error_message = error_json[k] except (KeyError, ValueError, TypeError): - error_message = result.content + pass if result.status_code == 401: raise GitlabAuthenticationError( -- cgit v1.2.1