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:
parent
b37e6187d4
commit
56c23d7c30
|
@ -1,5 +1,6 @@
|
||||||
import traceback
|
import traceback
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
|
from aiohttp import ClientResponseError
|
||||||
|
|
||||||
from sanic.log import log
|
from sanic.log import log
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class SanicTestClient:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response.json = await response.json()
|
response.json = await response.json()
|
||||||
except (JSONDecodeError, UnicodeDecodeError):
|
except (ClientResponseError, JSONDecodeError, UnicodeDecodeError):
|
||||||
response.json = None
|
response.json = None
|
||||||
|
|
||||||
response.body = await response.read()
|
response.body = await response.read()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user