mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-26 13:49:22 -05:00
Update user/alias query APIs to use new format of SimpleHttpClient.get_json
This commit is contained in:
parent
96d4bf9012
commit
6d3e4f4d0a
@ -13,8 +13,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.web.client import PartialDownloadError
|
|
||||||
|
|
||||||
|
from synapse.api.errors import CodeMessageException
|
||||||
from synapse.http.client import SimpleHttpClient
|
from synapse.http.client import SimpleHttpClient
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -42,11 +42,11 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||||||
})
|
})
|
||||||
if response: # just an empty json object
|
if response: # just an empty json object
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
except PartialDownloadError as e:
|
except CodeMessageException as e:
|
||||||
if e.status == 404:
|
if e.code == 404:
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
return
|
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
|
@defer.inlineCallbacks
|
||||||
def query_alias(self, service, alias):
|
def query_alias(self, service, alias):
|
||||||
@ -56,14 +56,13 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||||||
response = yield self.get_json(uri, {
|
response = yield self.get_json(uri, {
|
||||||
"access_token": self.hs_token
|
"access_token": self.hs_token
|
||||||
})
|
})
|
||||||
logger.info("%s", response[0])
|
|
||||||
if response: # just an empty json object
|
if response: # just an empty json object
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
except PartialDownloadError as e:
|
except CodeMessageException as e:
|
||||||
if e.status == 404:
|
if e.code == 404:
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
return
|
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):
|
def push_bulk(self, service, events):
|
||||||
pass
|
pass
|
||||||
|
@ -113,6 +113,9 @@ class SimpleHttpClient(object):
|
|||||||
if 200 <= response.code < 300:
|
if 200 <= response.code < 300:
|
||||||
defer.returnValue(json.loads(body))
|
defer.returnValue(json.loads(body))
|
||||||
else:
|
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)
|
raise CodeMessageException(response.code, body)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user