aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mastodon/Mastodon.py7
-rw-r--r--tests/test_errors.py20
2 files changed, 25 insertions, 2 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 3f594cf..98cebab 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -2214,9 +2214,12 @@ class Mastodon:
2214 if not response_object.ok: 2214 if not response_object.ok:
2215 try: 2215 try:
2216 response = response_object.json(object_hook=self.__json_hooks) 2216 response = response_object.json(object_hook=self.__json_hooks)
2217 if not isinstance(response, dict) or 'error' not in response: 2217 if isinstance(response, dict) and 'error' in response:
2218 error_msg = response['error']
2219 elif isinstance(response, str):
2220 error_msg = response
2221 else:
2218 error_msg = None 2222 error_msg = None
2219 error_msg = response['error']
2220 except ValueError: 2223 except ValueError:
2221 error_msg = None 2224 error_msg = None
2222 2225
diff --git a/tests/test_errors.py b/tests/test_errors.py
new file mode 100644
index 0000000..7329507
--- /dev/null
+++ b/tests/test_errors.py
@@ -0,0 +1,20 @@
1import pytest
2from mastodon.Mastodon import MastodonAPIError
3
4try:
5 from mock import MagicMock
6except ImportError:
7 from unittest.mock import MagicMock
8
9def test_nonstandard_errors(api):
10 response = MagicMock()
11 response.json = MagicMock(return_value=
12 "I am a non-standard instance and this error is a plain string.")
13 response.ok = False
14 session = MagicMock()
15 session.request = MagicMock(return_value=response)
16
17 api.session = session
18 with pytest.raises(MastodonAPIError):
19 api.instance()
20
Powered by cgit v1.2.3 (git 2.41.0)