mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-19 20:14:23 +01:00
Do the same for get_json
This commit is contained in:
parent
a1595cec78
commit
70caf49914
1 changed files with 21 additions and 8 deletions
|
@ -323,18 +323,31 @@ class MatrixProxyClient(object):
|
||||||
result = yield self.simpleHttpClient.post_json_get_json(uri, post_json)
|
result = yield self.simpleHttpClient.post_json_get_json(uri, post_json)
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
except CodeMessageException as cme:
|
except CodeMessageException as cme:
|
||||||
ex = None
|
ex = self._tryGetMatrixError(cme.msg)
|
||||||
try:
|
|
||||||
errbody = json.loads(cme.msg)
|
|
||||||
errcode = errbody['errcode']
|
|
||||||
errtext = errbody['error']
|
|
||||||
ex = SynapseError(cme.code, errtext, errcode)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
if ex is not None:
|
if ex is not None:
|
||||||
raise ex
|
raise ex
|
||||||
raise cme
|
raise cme
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_json(self, uri, args={}):
|
||||||
|
try:
|
||||||
|
result = yield self.simpleHttpClient.get_json(uri, args)
|
||||||
|
defer.returnValue(result)
|
||||||
|
except CodeMessageException as cme:
|
||||||
|
ex = self._tryGetMatrixError(cme.msg)
|
||||||
|
if ex is not None:
|
||||||
|
raise ex
|
||||||
|
raise cme
|
||||||
|
|
||||||
|
def _tryGetMatrixError(self, body):
|
||||||
|
try:
|
||||||
|
errbody = json.loads(body)
|
||||||
|
errcode = errbody['errcode']
|
||||||
|
errtext = errbody['error']
|
||||||
|
return SynapseError(cme.code, errtext, errcode)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
# XXX: FIXME: This is horribly copy-pasted from matrixfederationclient.
|
# XXX: FIXME: This is horribly copy-pasted from matrixfederationclient.
|
||||||
# The two should be factored out.
|
# The two should be factored out.
|
||||||
|
|
Loading…
Reference in a new issue