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:
Damir Jelić 2019-05-02 14:49:24 +02:00
parent a996d4acd3
commit 7f8d18d857

View File

@ -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,