handle non-json responses
This commit is contained in:
parent
3d67f6fb4d
commit
e0b111d7a9
12
heavynode.py
12
heavynode.py
@ -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)
|
||||
return await r.json()
|
||||
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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user