Merge pull request #158 from ControlPanel-gg/server_delete

fixed a bug: is ptero is down don't delete the server from our side
This commit is contained in:
AVMG 2021-08-02 16:47:53 +02:00 committed by GitHub
commit 692aee69ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View file

@ -90,8 +90,12 @@ class ServerController extends Controller
*/
public function destroy(Server $server)
{
$server->delete();
return redirect()->back()->with('success', 'server has been removed!');
try {
$server->delete();
return redirect()->route('admin.servers.index')->with('success', 'server removed');
} catch (Exception $e) {
return redirect()->route('admin.servers.index')->with('error', 'An exception has occurred while trying to remove a resource "' . $e->getMessage() . '"');
}
}
/**

View file

@ -111,7 +111,7 @@ class ServerController extends Controller
$server->delete();
return redirect()->route('servers.index')->with('success', 'server removed');
} catch (Exception $e) {
return redirect()->route('servers.index')->with('error', 'An exception has occurred while trying to remove a resource');
return redirect()->route('servers.index')->with('error', 'An exception has occurred while trying to remove a resource "' . $e->getMessage() . '"');
}
}

View file

@ -70,7 +70,8 @@ class Server extends Model
});
static::deleting(function (Server $server) {
Pterodactyl::client()->delete("/application/servers/{$server->pterodactyl_id}");
$response = Pterodactyl::client()->delete("/application/servers/{$server->pterodactyl_id}");
if ($response->failed()) throw new Exception($response['errors'][0]['code']);
});
}