Skip to content

Commit ac59a75

Browse files
committed
[mwclient#79] Improve error msg for invalid json response
1 parent 9479172 commit ac59a75

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mwclient/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def raw_api(self, action, *args, **kwargs):
313313
except ValueError:
314314
if res.startswith('MediaWiki API is not enabled for this site.'):
315315
raise errors.APIDisabledError
316-
raise ValueError('Could not decode JSON: %s' % res)
316+
raise errors.InvalidResponse(res)
317317

318318
def raw_index(self, action, *args, **kwargs):
319319
"""Sends a call to index.php rather than the API."""

mwclient/errors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,16 @@ class NoSpecifiedEmail(EmailError):
5656

5757
class NoWriteApi(MwClientError):
5858
pass
59+
60+
61+
class InvalidResponse(MwClientError):
62+
63+
def __init__(self, response_text=None):
64+
self.message = 'Did not get a valid JSON response from the server. Check that ' + \
65+
'you used the correct hostname. If you did, the server might ' + \
66+
'be wrongly configured or experience temporary problems.'
67+
self.response_text = response_text
68+
MwClientError.__init__(self, self.message, response_text)
69+
70+
def __str__(self):
71+
return self.message

0 commit comments

Comments
 (0)