diff options
author | Kegan Dougal <kegan@matrix.org> | 2015-02-04 17:32:44 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2015-02-04 17:32:44 +0000 |
commit | 6d3e4f4d0aad4ad9b44b28349838ff48aef39440 (patch) | |
tree | 2a1b2a8c6675fe85fb5b3da350a2600bd83d0e02 /synapse | |
parent | Modify API for SimpleHttpClient.get_json and update usages. (diff) | |
download | synapse-6d3e4f4d0aad4ad9b44b28349838ff48aef39440.tar.xz |
Update user/alias query APIs to use new format of SimpleHttpClient.get_json
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/appservice/api.py | 15 | ||||
-rw-r--r-- | synapse/http/client.py | 3 |
2 files changed, 10 insertions, 8 deletions
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index 799ada96df..74508ecddf 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. from twisted.internet import defer -from twisted.web.client import PartialDownloadError +from synapse.api.errors import CodeMessageException from synapse.http.client import SimpleHttpClient import logging @@ -42,11 +42,11 @@ class ApplicationServiceApi(SimpleHttpClient): }) if response: # just an empty json object defer.returnValue(True) - except PartialDownloadError as e: - if e.status == 404: + except CodeMessageException as e: + if e.code == 404: defer.returnValue(False) return - logger.warning("query_user to %s received %s", (uri, e.status)) + logger.warning("query_user to %s received %s", uri, e.code) @defer.inlineCallbacks def query_alias(self, service, alias): @@ -56,14 +56,13 @@ class ApplicationServiceApi(SimpleHttpClient): response = yield self.get_json(uri, { "access_token": self.hs_token }) - logger.info("%s", response[0]) if response: # just an empty json object defer.returnValue(True) - except PartialDownloadError as e: - if e.status == 404: + except CodeMessageException as e: + if e.code == 404: defer.returnValue(False) return - logger.warning("query_alias to %s received %s", (uri, e.status)) + logger.warning("query_alias to %s received %s", uri, e.code) def push_bulk(self, service, events): pass diff --git a/synapse/http/client.py b/synapse/http/client.py index 5f4558be47..fee8c901a2 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -113,6 +113,9 @@ class SimpleHttpClient(object): if 200 <= response.code < 300: defer.returnValue(json.loads(body)) else: + # NB: This is explicitly not json.loads(body)'d because the contract + # of CodeMessageException is a *string* message. Callers can always + # load it into JSON if they want. raise CodeMessageException(response.code, body) |