def _validate_response(cls, response: aiohttp.client.ClientResponse) -> Awaitable[aiohttp.client.ClientResponse]:
"""
Takes in a HTTP response, looks through it to see if its legit, if not raise some errors.
If all is good return the response
:param response: aiohttp response
:return: aiohttp response
"""
if 400 <= response.status < 600:
if response.headers.get('Content-Type') == 'application/json':
json_data = await response.json()
cls._raise_error(response.status, errors=json_data.get('errors'))
else:
text = await response.text()
cls._raise_error(response.status, message=text)
else:
return response
评论列表
文章目录