handle non-json responses
This commit is contained in:
		
							
								
								
									
										12
									
								
								heavynode.py
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								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)
 | 
				
			||||||
        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):
 | 
					    async def send_command(self, cmd):
 | 
				
			||||||
        """Send console command to minecraft server."""
 | 
					        """Send console command to minecraft server."""
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user