Delete server on 404 instead of giving 500
This commit is contained in:
parent
21af9d9e77
commit
c26a47a982
|
@ -287,7 +287,7 @@ class Pterodactyl
|
||||||
* @param int $pterodactylId
|
* @param int $pterodactylId
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function getServerAttributes(int $pterodactylId)
|
public static function getServerAttributes(int $pterodactylId, bool $deleteOn404 = false)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = self::client()->get("/application/servers/{$pterodactylId}?include=egg,node,nest,location");
|
$response = self::client()->get("/application/servers/{$pterodactylId}?include=egg,node,nest,location");
|
||||||
|
@ -299,7 +299,13 @@ class Pterodactyl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($response->failed()) throw self::getException("Failed to get server attributes from pterodactyl - ", $response->status());
|
if ($response->failed()){
|
||||||
|
if($deleteOn404){ //Delete the server if it does not exist (server deleted on pterodactyl)
|
||||||
|
Server::where('pterodactyl_id', $pterodactylId)->first()->delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else throw self::getException("Failed to get server attributes from pterodactyl - ", $response->status());
|
||||||
|
}
|
||||||
return $response->json()['attributes'];
|
return $response->json()['attributes'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ class ServerController extends Controller
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
|
|
||||||
//Get server infos from ptero
|
//Get server infos from ptero
|
||||||
$serverAttributes = Pterodactyl::getServerAttributes($server->pterodactyl_id);
|
$serverAttributes = Pterodactyl::getServerAttributes($server->pterodactyl_id, true);
|
||||||
|
if(!$serverAttributes) continue;
|
||||||
$serverRelationships = $serverAttributes['relationships'];
|
$serverRelationships = $serverAttributes['relationships'];
|
||||||
$serverLocationAttributes = $serverRelationships['location']['attributes'];
|
$serverLocationAttributes = $serverRelationships['location']['attributes'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue