Catch the proper exception when waiting for a json response on a non-json handler

I'm trying to test a simple handler that returns `text('OK')`.
The `await response.json()` statement will throw a `ClientResponseError` since obviously I dont have 'application/json' in my content-type response header (see client_reqrep.py line #717).
That error isn't caught which causes test to fail...
This commit is contained in:
Eran Kampf 2017-06-19 13:25:32 -07:00 committed by GitHub
parent b37e6187d4
commit 56c23d7c30

View File

@ -1,5 +1,6 @@
import traceback
from json import JSONDecodeError
from aiohttp import ClientResponseError
from sanic.log import log
@ -32,7 +33,7 @@ class SanicTestClient:
try:
response.json = await response.json()
except (JSONDecodeError, UnicodeDecodeError):
except (ClientResponseError, JSONDecodeError, UnicodeDecodeError):
response.json = None
response.body = await response.read()