From c57b4c1210f9ed001a4f263ca64cf894c84d94d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 11 Apr 2019 14:23:32 +0200 Subject: [PATCH] daemon: Catch content type errors. --- pantalaimon/daemon.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 882cbd4..9481835 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -12,6 +12,7 @@ import attr import click import logbook from aiohttp import ClientSession, web +from aiohttp.client_exceptions import ContentTypeError from appdirs import user_data_dir from logbook import StderrHandler from multidict import CIMultiDict @@ -194,7 +195,7 @@ class ProxyDaemon: async def login(self, request): try: body = await request.json() - except JSONDecodeError: + except (JSONDecodeError, ContentTypeError): # After a long debugging session the culprit ended up being aiohttp # and a similar bug to # https://github.com/aio-libs/aiohttp/issues/2277 but in the server @@ -220,7 +221,7 @@ class ProxyDaemon: try: json_response = await response.json() - except JSONDecodeError: + except (JSONDecodeError, ContentTypeError): json_response = None pass @@ -355,7 +356,7 @@ class ProxyDaemon: try: content = await request.json() - except JSONDecodeError: + except (JSONDecodeError, ContentTypeError): return self._not_json try: