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,7 +523,7 @@ class ProxyDaemon:
|
||||
return web.Response(status=500, text=str(e))
|
||||
|
||||
if response.status == 200:
|
||||
# TODO this can fail even on a 200.
|
||||
try:
|
||||
json_response = await response.json()
|
||||
json_response = await self.decrypt_sync(client, json_response)
|
||||
|
||||
@ -531,6 +531,8 @@ class ProxyDaemon:
|
||||
status=response.status,
|
||||
text=json.dumps(json_response)
|
||||
)
|
||||
except (JSONDecodeError, ContentTypeError):
|
||||
pass
|
||||
|
||||
return web.Response(
|
||||
status=response.status,
|
||||
@ -556,6 +558,7 @@ class ProxyDaemon:
|
||||
return web.Response(status=500, text=str(e))
|
||||
|
||||
if response.status == 200:
|
||||
try:
|
||||
json_response = await response.json()
|
||||
json_response = client.decrypt_messages_body(json_response)
|
||||
|
||||
@ -563,6 +566,8 @@ class ProxyDaemon:
|
||||
status=response.status,
|
||||
text=json.dumps(json_response)
|
||||
)
|
||||
except (JSONDecodeError, ContentTypeError):
|
||||
pass
|
||||
|
||||
return web.Response(
|
||||
status=response.status,
|
||||
|
Loading…
Reference in New Issue
Block a user