Fixed a bug. Improved error handling. Small cleanup of code

This commit is contained in:
Marcel Baumgartner 2024-04-17 15:42:51 +02:00
parent dcfb836b39
commit 90eed5c74c
3 changed files with 51 additions and 44 deletions

View file

@ -99,9 +99,11 @@ public class ServerConsole : IDisposable
}
catch (Exception e)
{
if (e is not WebSocketException)
if (e is WebSocketException)
Logger.Warn($"Lost connection to daemon server websocket: {e.Message}");
else
{
Logger.Warn("Lost connection to daemon server websocket");
Logger.Warn("Server console ws disconnected because of application error:");
Logger.Warn(e);
}

View file

@ -113,13 +113,7 @@
<ServerNavigation Index="@GetIndex()" ServerId="@Id"/>
<div class="mt-3">
@if (IsInstalling)
{
<div class="card card-body bg-black p-3">
<Terminal @ref="InstallTerminal" EnableClipboard="false"/>
</div>
}
else if (IsConsoleDisconnected)
@if (IsConsoleDisconnected)
{
<IconAlert Title="Connection to server lost" Color="danger" Icon="bx-error">
We lost the connection to the server. Please refresh the page in order to retry. If this error persists please contact the support
@ -137,6 +131,12 @@
The node this server is on is still booting. Please refresh the page in order to retry. If this error persists please contact the support
</IconAlert>
}
else if (IsInstalling)
{
<div class="card card-body bg-black p-3">
<Terminal @ref="InstallTerminal" EnableClipboard="false"/>
</div>
}
else
{
<CascadingValue Value="Server">
@ -217,37 +217,7 @@
Console = new ServerConsole(Server);
// Configure
Console.OnStateChange += async state =>
{
// General rerender to update the state text in the ui
// NOTE: Obsolete because of the update timer
//await InvokeAsync(StateHasChanged);
// Change from offline to installing
// This will trigger the initialisation of the install view
if (state == ServerState.Installing && !IsInstalling)
{
IsInstalling = true;
// After this call, we should have access to the install terminal reference
await InvokeAsync(StateHasChanged);
Console.OnNewMessage += OnInstallConsoleMessage;
}
// Change from installing to offline
// This will trigger the destruction of the install view
else if (state == ServerState.Offline && IsInstalling)
{
IsInstalling = false;
Console.OnNewMessage -= OnInstallConsoleMessage;
// After this call, the install terminal will disappear
await InvokeAsync(StateHasChanged);
await ToastService.Info("Server installation complete");
}
};
Console.OnStateChange += async state => await HandleStateChange(state);
Console.OnDisconnected += async () =>
{
@ -267,7 +237,7 @@
await InvokeAsync(StateHasChanged);
return;
}
// We want to check if its an connection error, if yes we want to show the user that its an error with the connection
// If not we proceed with the throwing for the soft error handler.
@ -288,6 +258,41 @@
}
UpdateTimer = new Timer(async _ => { await InvokeAsync(StateHasChanged); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
var state = await ServerService.GetState(Server);
await HandleStateChange(state);
}
private async Task HandleStateChange(ServerState state)
{
// General rerender to update the state text in the ui
// NOTE: Obsolete because of the update timer
//await InvokeAsync(StateHasChanged);
// Change from offline to installing
// This will trigger the initialisation of the install view
if (state == ServerState.Installing && !IsInstalling)
{
IsInstalling = true;
// After this call, we should have access to the install terminal reference
await InvokeAsync(StateHasChanged);
Console.OnNewMessage += OnInstallConsoleMessage;
}
// Change from installing to offline
// This will trigger the destruction of the install view
else if (state == ServerState.Offline && IsInstalling)
{
IsInstalling = false;
Console.OnNewMessage -= OnInstallConsoleMessage;
// After this call, the install terminal will disappear
await InvokeAsync(StateHasChanged);
await ToastService.Info("Server installation complete");
}
}
private async Task OnInstallConsoleMessage(string message)
@ -334,7 +339,7 @@
case "/network":
return 2;
case "/schedules":
return 7;

View file

@ -74,8 +74,7 @@
<Folder Include="Features\FileManager\Http\Requests\" />
<Folder Include="Features\FileManager\Http\Resources\" />
<Folder Include="Features\Servers\Http\Resources\" />
<Folder Include="storage\assetOverrides\x\y\" />
<Folder Include="storage\logs\" />
<Folder Include="storage\" />
<Folder Include="Styles\" />
<Folder Include="wwwroot\css\" />
</ItemGroup>
@ -114,6 +113,7 @@
<_ContentIncludedByDefault Remove="Features\FileManager\UI\Components\FileManager.razor" />
<_ContentIncludedByDefault Remove="Features\FileManager\UI\Components\FileUploader.razor" />
<_ContentIncludedByDefault Remove="Features\FileManager\UI\Components\FileView.razor" />
<_ContentIncludedByDefault Remove="storage\configs\core.json" />
</ItemGroup>
</Project>