daemon: Catch content type errors.

This commit is contained in:
Damir Jelić 2019-04-11 14:23:32 +02:00
parent b1444568d4
commit c57b4c1210

View File

@ -12,6 +12,7 @@ import attr
import click import click
import logbook import logbook
from aiohttp import ClientSession, web from aiohttp import ClientSession, web
from aiohttp.client_exceptions import ContentTypeError
from appdirs import user_data_dir from appdirs import user_data_dir
from logbook import StderrHandler from logbook import StderrHandler
from multidict import CIMultiDict from multidict import CIMultiDict
@ -194,7 +195,7 @@ class ProxyDaemon:
async def login(self, request): async def login(self, request):
try: try:
body = await request.json() body = await request.json()
except JSONDecodeError: except (JSONDecodeError, ContentTypeError):
# After a long debugging session the culprit ended up being aiohttp # After a long debugging session the culprit ended up being aiohttp
# and a similar bug to # and a similar bug to
# https://github.com/aio-libs/aiohttp/issues/2277 but in the server # https://github.com/aio-libs/aiohttp/issues/2277 but in the server
@ -220,7 +221,7 @@ class ProxyDaemon:
try: try:
json_response = await response.json() json_response = await response.json()
except JSONDecodeError: except (JSONDecodeError, ContentTypeError):
json_response = None json_response = None
pass pass
@ -355,7 +356,7 @@ class ProxyDaemon:
try: try:
content = await request.json() content = await request.json()
except JSONDecodeError: except (JSONDecodeError, ContentTypeError):
return self._not_json return self._not_json
try: try: