diff --git a/wikibaseintegrator/wbi_exceptions.py b/wikibaseintegrator/wbi_exceptions.py index 648e762d..8440f8fc 100644 --- a/wikibaseintegrator/wbi_exceptions.py +++ b/wikibaseintegrator/wbi_exceptions.py @@ -5,6 +5,7 @@ class MWApiError(Exception): """ Base class for MediaWiki API error handling """ + error_dict: Dict[str, Any] code: str info: str messages: List[Dict[str, Any]] @@ -41,15 +42,17 @@ def get_languages(self) -> List[str]: ) def __init__(self, error_dict: Dict[str, Any]): - if 'info' in error_dict: - self.info = error_dict['info'] + self.error_dict = error_dict + + if 'info' in self.error_dict: + self.info = self.error_dict['info'] else: self.info = 'MWApiError' super().__init__(self.info) - self.code = error_dict['code'] if 'code' in error_dict else 'wikibaseintegrator-missing-error-code' - if 'messages' in error_dict: - self.messages = error_dict['messages'] - self.messages_names = [message['name'] for message in error_dict['messages']] + self.code = self.error_dict['code'] if 'code' in error_dict else 'wikibaseintegrator-missing-error-code' + if 'messages' in self.error_dict: + self.messages = self.error_dict['messages'] + self.messages_names = [message['name'] for message in self.error_dict['messages']] else: self.messages = [{'html': {'*': 'WikibaseIntegrator: missing message from HTML return.'}, 'name': 'wikibaseintegrator-missing-messages'}] self.messages_names = ['wikibaseintegrator-missing-messages'] diff --git a/wikibaseintegrator/wbi_helpers.py b/wikibaseintegrator/wbi_helpers.py index 2c539b9b..9108c044 100644 --- a/wikibaseintegrator/wbi_helpers.py +++ b/wikibaseintegrator/wbi_helpers.py @@ -122,7 +122,7 @@ def mediawiki_api_call(method: str, mediawiki_api_url: Optional[str] = None, ses raise ModificationFailed(json_data['error']) # others case - raise MWApiError(json_data) + raise MWApiError(json_data['error']) # there is no error or waiting. break out of this loop and parse response break