handle non-json responses
This commit is contained in:
parent
3d67f6fb4d
commit
e0b111d7a9
10
heavynode.py
10
heavynode.py
@ -22,7 +22,10 @@ class Client:
|
|||||||
# hang out in a pending state until someone else does
|
# hang out in a pending state until someone else does
|
||||||
|
|
||||||
async def make_request(self, method, path, *args, **kwargs):
|
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:
|
if 'headers' in kwargs:
|
||||||
kwargs['headers'].update(h)
|
kwargs['headers'].update(h)
|
||||||
else:
|
else:
|
||||||
@ -35,7 +38,12 @@ class Client:
|
|||||||
r = await self.session.request(method, url, *args, **kwargs)
|
r = await self.session.request(method, url, *args, **kwargs)
|
||||||
if r.status >= 400:
|
if r.status >= 400:
|
||||||
raise HttpError(f'Request failed with status code {r.status}', r)
|
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()
|
return await r.json()
|
||||||
|
else:
|
||||||
|
return await r.text
|
||||||
|
|
||||||
async def send_command(self, cmd):
|
async def send_command(self, cmd):
|
||||||
"""Send console command to minecraft server."""
|
"""Send console command to minecraft server."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user