fix: catch and handle JSONDecodeError
This commit is contained in:
parent
c59b11a950
commit
4d4ad4a6d6
1 changed files with 9 additions and 2 deletions
|
@ -4,6 +4,7 @@ from multiprocessing.sharedctypes import Value
|
|||
from typing import Optional, Dict, Any
|
||||
|
||||
import aiohttp
|
||||
from json.decoder import JSONDecodeError
|
||||
|
||||
from ..definitions import GameProfile
|
||||
|
||||
|
@ -66,7 +67,10 @@ class AuthInterface:
|
|||
async def _post(cls, endpoint:str, **kwargs) -> Dict[str, Any]:
|
||||
async with aiohttp.ClientSession(timeout=cls.TIMEOUT) as session:
|
||||
async with session.post(endpoint, **kwargs) as res:
|
||||
data = await res.json(content_type=None)
|
||||
try:
|
||||
data = await res.json(content_type=None)
|
||||
except JSONDecodeError:
|
||||
raise AuthException(endpoint, res.status, {"invalid": await res.text()}, kwargs)
|
||||
logger.debug("POST /%s [%s] : %s", endpoint, str(kwargs), str(data))
|
||||
if res.status >= 400:
|
||||
raise AuthException(endpoint, res.status, data, kwargs)
|
||||
|
@ -76,7 +80,10 @@ class AuthInterface:
|
|||
async def _get(cls, endpoint:str, **kwargs) -> Dict[str, Any]:
|
||||
async with aiohttp.ClientSession(timeout=cls.TIMEOUT) as session:
|
||||
async with session.get(endpoint, **kwargs) as res:
|
||||
data = await res.json(content_type=None)
|
||||
try:
|
||||
data = await res.json(content_type=None)
|
||||
except JSONDecodeError:
|
||||
raise AuthException(endpoint, res.status, {"invalid": await res.text()}, kwargs)
|
||||
logger.debug("GET /%s [%s] : %s", endpoint, str(kwargs), str(data))
|
||||
if res.status >= 400:
|
||||
raise AuthException(endpoint, res.status, data, kwargs)
|
||||
|
|
Loading…
Reference in a new issue