From ea52148aab998f418e4ac1b52962f26460e77785 Mon Sep 17 00:00:00 2001 From: Onebrownsound Date: Thu, 9 May 2024 16:01:07 +0000 Subject: [PATCH] Ward off unexpected missing properties when handling exceptions within exceptions.py --- vimeo/exceptions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vimeo/exceptions.py b/vimeo/exceptions.py index 23d8743..0c2b3c0 100644 --- a/vimeo/exceptions.py +++ b/vimeo/exceptions.py @@ -6,7 +6,8 @@ class BaseVimeoException(Exception): def __get_message(self, response): if type(response) is Exception: - return response.message + default_message = 'There was an unexpected error' + return response.message if response.message is not None else default_message json = None try: @@ -14,12 +15,13 @@ def __get_message(self, response): except Exception: pass + message = None if json: message = json.get('error') or json.get('Description') elif hasattr(response, 'text'): response_message = getattr(response, 'message', 'There was an unexpected error.') message = getattr(response, 'text', response_message) - else: + elif hasattr(response, 'message'):: message = getattr(response, 'message') return message