jenkins-bot has submitted this change and it was merged.
Change subject: Include response info in APIError message
......................................................................
Include response info in APIError message
requestid exists for 1.14+ (606d9219)
servedby exists for 1.17+ (18d8635d)
Change-Id: I13961539e713242cfa244d753c43cad14271fecc
---
M pywikibot/data/api.py
M tests/api_tests.py
2 files changed, 26 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index d838f0c..b9df112 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -105,6 +105,14 @@
def __str__(self):
"""Return a string representation."""
+ if self.other:
+ return '{0}: {1} [{2}]'.format(
+ self.code,
+ self.info,
+ '; '.join(
+ '{0}:{1}'.format(key, val)
+ for key, val in self.other.items()))
+
return "%(code)s: %(info)s" % self.__dict__
@@ -2005,8 +2013,17 @@
# retry the previous query
continue
self._handle_warnings(result)
+
if "error" not in result:
return result
+
+ error = result['error'].copy()
+ for key in result:
+ if key == 'error':
+ continue
+ assert key not in error
+ assert isinstance(result[key], basestring)
+ error[key] = result[key]
if "*" in result["error"]:
# help text returned
@@ -2029,13 +2046,17 @@
if code.startswith(u'internal_api_error_'):
class_name = code[len(u'internal_api_error_'):]
+
+ del error['code'] # is added via class_name
+ e = APIMWException(class_name, **error)
+
retry = class_name in ['DBConnectionError', # bug 62974
'DBQueryError', # bug 58158
'ReadOnlyError' # bug 59227
]
pywikibot.error("Detected MediaWiki API exception %s%s"
- % (class_name,
+ % (e,
"; retrying" if retry else "; raising"))
# Due to bug T66958, Page's repr may return non ASCII bytes
# Get as bytes in PY2 and decode with the console encoding as
@@ -2054,8 +2075,7 @@
self.wait()
continue
- del result['error']['code'] # is added via class_name
- raise APIMWException(class_name, **result['error'])
+ raise e
# bugs 46535, 62126, 64494, 66619
# maybe removed when it 46535 is solved
diff --git a/tests/api_tests.py b/tests/api_tests.py
index b898c4a..6cb0c83 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -40,7 +40,9 @@
"""Test raising an APIMWException."""
data = {'error': {'code': 'internal_api_error_fake',
- 'info': 'Fake error message'}}
+ 'info': 'Fake error message'},
+ 'servedby': 'unittest',
+ }
def _dummy_request(self, **kwargs):
self.assertIn('body', kwargs)
--
To view, visit https://gerrit.wikimedia.org/r/233204
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I13961539e713242cfa244d753c43cad14271fecc
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>