diff options
Diffstat (limited to 'gitlab/exceptions.py')
| -rw-r--r-- | gitlab/exceptions.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index c7d1da6..6c00129 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -39,6 +39,10 @@ class GitlabAuthenticationError(GitlabError): pass +class GitlabParsingError(GitlabError): + pass + + class GitlabConnectionError(GitlabError): pass @@ -47,6 +51,10 @@ class GitlabOperationError(GitlabError): pass +class GitlabHttpError(GitlabError): + pass + + class GitlabListError(GitlabOperationError): pass @@ -202,3 +210,23 @@ def raise_error_from_response(response, error, expected_code=200): raise error(error_message=message, response_code=response.status_code, response_body=response.content) + + +def on_http_error(error): + """Manage GitlabHttpError exceptions. + + This decorator function can be used to catch GitlabHttpError exceptions + raise specialized exceptions instead. + + Args: + error(Exception): The exception type to raise -- must inherit from + GitlabError + """ + def wrap(f): + def wrapped_f(*args, **kwargs): + try: + return f(*args, **kwargs) + except GitlabHttpError as e: + raise error(e.response_code, e.error_message) + return wrapped_f + return wrap |
