diff options
author | David Baker <dave@matrix.org> | 2017-04-21 16:09:03 +0100 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2017-04-21 16:09:03 +0100 |
commit | 70caf499142a3bc5e5a6e6228471983326d6e147 (patch) | |
tree | f3884c80baedae026b4ac96943a9bde71eba938b /synapse | |
parent | Don't error for 3xx responses (diff) | |
download | synapse-70caf499142a3bc5e5a6e6228471983326d6e147.tar.xz |
Do the same for get_json
Diffstat (limited to '')
-rw-r--r-- | synapse/http/client.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py index 483f37fe03..4458855cec 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -323,18 +323,31 @@ class MatrixProxyClient(object): result = yield self.simpleHttpClient.post_json_get_json(uri, post_json) defer.returnValue(result) except CodeMessageException as cme: - ex = None - try: - errbody = json.loads(cme.msg) - errcode = errbody['errcode'] - errtext = errbody['error'] - ex = SynapseError(cme.code, errtext, errcode) - except: - pass + ex = self._tryGetMatrixError(cme.msg) if ex is not None: raise ex 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. # The two should be factored out. |