Added error handling in server backup (soft error handler). Added status code get accessor to api exceptions

This commit is contained in:
Marcel Baumgartner
2023-04-15 22:11:57 +02:00
parent 227ad493b7
commit 8c220e6576
5 changed files with 45 additions and 33 deletions

View File

@@ -5,7 +5,7 @@ namespace Moonlight.App.Exceptions;
[Serializable] [Serializable]
public class DaemonException : Exception public class DaemonException : Exception
{ {
public int StatusCode { private get; set; } public int StatusCode { get; set; }
public DaemonException() public DaemonException()
{ {

View File

@@ -5,7 +5,7 @@ namespace Moonlight.App.Exceptions;
[Serializable] [Serializable]
public class PleskException : Exception public class PleskException : Exception
{ {
public int StatusCode { private get; set; } public int StatusCode { get; set; }
public PleskException() public PleskException()
{ {

View File

@@ -5,7 +5,7 @@ namespace Moonlight.App.Exceptions;
[Serializable] [Serializable]
public class WingsException : Exception public class WingsException : Exception
{ {
public int StatusCode { private get; set; } public int StatusCode { get; set; }
public WingsException() public WingsException()
{ {

View File

@@ -57,6 +57,10 @@ else
SmartTranslateService.Translate("Error from daemon"), SmartTranslateService.Translate("Error from daemon"),
wingsException.Message wingsException.Message
); );
//TODO: Error log service
Logger.Warn($"Wings exception status code: {wingsException.StatusCode}");
} }
else if (exception is PleskException pleskException) else if (exception is PleskException pleskException)
{ {

View File

@@ -185,25 +185,26 @@
} }
private async Task Download(ServerBackup serverBackup) private async Task Download(ServerBackup serverBackup)
{
try
{ {
var url = await ServerService.DownloadBackup(CurrentServer, serverBackup); var url = await ServerService.DownloadBackup(CurrentServer, serverBackup);
NavigationManager.NavigateTo(url); NavigationManager.NavigateTo(url);
await ToastService.Success(SmartTranslateService.Translate("Backup download successfully started")); await ToastService.Success(SmartTranslateService.Translate("Backup download successfully started"));
/*
try
{
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Warn("Error starting backup download"); Logger.Warn("Error starting backup download");
Logger.Warn(e); Logger.Warn(e);
await ToastService.Error(SmartTranslateService.Translate("Backup download failed")); await ToastService.Error(SmartTranslateService.Translate("Backup download failed"));
} }*/
} }
private async Task CopyUrl(ServerBackup serverBackup) private async Task CopyUrl(ServerBackup serverBackup)
{
try
{ {
var url = await ServerService.DownloadBackup(CurrentServer, serverBackup); var url = await ServerService.DownloadBackup(CurrentServer, serverBackup);
@@ -211,61 +212,68 @@
await AlertService.Success( await AlertService.Success(
SmartTranslateService.Translate("Success"), SmartTranslateService.Translate("Success"),
SmartTranslateService.Translate("Backup URL successfully copied to your clipboard")); SmartTranslateService.Translate("Backup URL successfully copied to your clipboard"));
/*
try
{
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Warn("Error copying backup url"); Logger.Warn("Error copying backup url");
Logger.Warn(e); Logger.Warn(e);
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while generating backup url")); await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while generating backup url"));
} }*/
} }
private async Task Delete(ServerBackup serverBackup) private async Task Delete(ServerBackup serverBackup)
{
try
{ {
await ToastService.Info(SmartTranslateService.Translate("Backup deletion started")); await ToastService.Info(SmartTranslateService.Translate("Backup deletion started"));
await ServerService.DeleteBackup(CurrentServer, serverBackup); await ServerService.DeleteBackup(CurrentServer, serverBackup);
/*
try
{
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Warn("Error deleting backup"); Logger.Warn("Error deleting backup");
Logger.Warn(e); Logger.Warn(e);
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while starting backup deletion")); await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while starting backup deletion"));
} }*/
} }
private async Task Restore(ServerBackup serverBackup) private async Task Restore(ServerBackup serverBackup)
{ {
await ServerService.RestoreBackup(CurrentServer, serverBackup);
await ToastService.Info(SmartTranslateService.Translate("Backup restore started"));
/*
try try
{ {
await ServerService.RestoreBackup(CurrentServer, serverBackup);
await ToastService.Info(SmartTranslateService.Translate("Backup restore started"));
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Warn("Error restoring backup"); Logger.Warn("Error restoring backup");
Logger.Warn(e); Logger.Warn(e);
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while restoring a backup")); await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while restoring a backup"));
} }*/
} }
private async Task Create() private async Task Create()
{
try
{ {
await ToastService.Info(SmartTranslateService.Translate("Started backup creation")); await ToastService.Info(SmartTranslateService.Translate("Started backup creation"));
var backup = await ServerService.CreateBackup(CurrentServer); await ServerService.CreateBackup(CurrentServer);
/* /*
try
{
// Modify the backup list so no reload needed. Also the create event will work // Modify the backup list so no reload needed. Also the create event will work
var list = AllBackups!.ToList(); //var list = AllBackups!.ToList();
list.Add(backup); //list.Add(backup);
AllBackups = list.ToArray(); //AllBackups = list.ToArray();
*/
await LazyLoader.Reload(); await LazyLoader.Reload();
} }
@@ -274,7 +282,7 @@
Logger.Warn("Error creating backup"); Logger.Warn("Error creating backup");
Logger.Warn(e); Logger.Warn(e);
await ToastService.Error(SmartTranslateService.Translate("An unknown error has occured while creating a backup")); await ToastService.Error(SmartTranslateService.Translate("An unknown error has occured while creating a backup"));
} }*/
} }
private async Task OnContextMenuClick(ItemClickEventArgs args) private async Task OnContextMenuClick(ItemClickEventArgs args)