mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-09 06:37:55 -05:00
daemon: Handle json errors in the sync and messages methods.
A valid 200 response from the server doesn't necessarily mean that the content will be valid json. Handle decode errors and return the raw body if we're unable to decode.
This commit is contained in:
parent
a996d4acd3
commit
7f8d18d857
@ -523,14 +523,16 @@ class ProxyDaemon:
|
|||||||
return web.Response(status=500, text=str(e))
|
return web.Response(status=500, text=str(e))
|
||||||
|
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
# TODO this can fail even on a 200.
|
try:
|
||||||
json_response = await response.json()
|
json_response = await response.json()
|
||||||
json_response = await self.decrypt_sync(client, json_response)
|
json_response = await self.decrypt_sync(client, json_response)
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=response.status,
|
status=response.status,
|
||||||
text=json.dumps(json_response)
|
text=json.dumps(json_response)
|
||||||
)
|
)
|
||||||
|
except (JSONDecodeError, ContentTypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=response.status,
|
status=response.status,
|
||||||
@ -556,13 +558,16 @@ class ProxyDaemon:
|
|||||||
return web.Response(status=500, text=str(e))
|
return web.Response(status=500, text=str(e))
|
||||||
|
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
json_response = await response.json()
|
try:
|
||||||
json_response = client.decrypt_messages_body(json_response)
|
json_response = await response.json()
|
||||||
|
json_response = client.decrypt_messages_body(json_response)
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=response.status,
|
status=response.status,
|
||||||
text=json.dumps(json_response)
|
text=json.dumps(json_response)
|
||||||
)
|
)
|
||||||
|
except (JSONDecodeError, ContentTypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=response.status,
|
status=response.status,
|
||||||
|
Loading…
Reference in New Issue
Block a user