handle non-json responses

This commit is contained in:
Joseph Montanaro 2020-06-19 23:10:58 -07:00
parent 3d67f6fb4d
commit e0b111d7a9

View File

@ -22,7 +22,10 @@ class Client:
# hang out in a pending state until someone else does
async def make_request(self, method, path, *args, **kwargs):
h = {'Authorization': f'Bearer {self.token}'}
h = {
'Authorization': f'Bearer {self.token}',
'Accept': 'Application/vnd.pterodactyl.v1+json',
}
if 'headers' in kwargs:
kwargs['headers'].update(h)
else:
@ -35,7 +38,12 @@ class Client:
r = await self.session.request(method, url, *args, **kwargs)
if r.status >= 400:
raise HttpError(f'Request failed with status code {r.status}', r)
elif r.status == 204:
return None # no content
elif r.headers['Content-Type'].lower() in {'application/json', 'application/vnd.pterodactyl.v1+json'}:
return await r.json()
else:
return await r.text
async def send_command(self, cmd):
"""Send console command to minecraft server."""