FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Changed error behavior · python-webuntis/python-webuntis@67d6fa2 · GitHub

Commit 67d6fa2

Browse files
committed
Changed error behavior
1 parent 44f5f72 commit 67d6fa2

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎webuntis/tests/utils/test_remote.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_parse_result(self):
1414

1515
a = b = {'id': 2}
1616
self.assertRaisesRegex(webuntis.errors.RemoteError,
17-
'JSON-RPC', x, a, b)
17+
'no information', x, a, b)
1818

1919
a = {'id': 2}
2020
b = {'id': 2, 'result': 'YESSIR'}
@@ -25,11 +25,11 @@ def test_parse_error_code(self):
2525

2626
a = b = {}
2727
self.assertRaisesRegex(webuntis.errors.RemoteError,
28-
'JSON-RPC', x, a, b)
28+
'no information', x, a, b)
2929

30-
b = {'error': {'code': 0, 'message': 'hello'}}
30+
b = {'error': {'code': 0, 'message': 'hello world'}}
3131
self.assertRaisesRegex(webuntis.errors.RemoteError,
32-
'JSON-RPC', x, a, b)
32+
'hello world', x, a, b)
3333

3434
for code, exc in webuntis.utils.remote._errorcodes.items():
3535
self.assertRaises(exc, x, a, {

‎webuntis/utils/remote.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,19 @@ def _parse_error_code(request_body, result_body):
108108
log('error', result_body)
109109
try:
110110
error = result_body[u'error']
111-
exc = _errorcodes[error[u'code']](error[u'message'])
111+
code, message = error[u'code'], error[u'message']
112112
except KeyError:
113-
exc = errors.RemoteError(
114-
('Some JSON-RPC-ish error happened. Please report this to the '
115-
'developer so he can implement a proper handling.'),
116-
result_body, request_body
117-
)
113+
code = None # None doesn't exist in_errorcodes
114+
message = ('Some error happened and there is no information provided '
115+
'what went wrong.')
118116

119-
raise exc
117+
cls = _errorcodes.get(code, errors.RemoteError)
118+
119+
raise cls(
120+
message,
121+
result_body,
122+
request_body
123+
)
120124

121125

122126
def _send_request(url, data, headers):

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL