Improve error handling

This commit is contained in:
Liza 2023-02-24 11:18:03 +01:00
parent 17f7dcdf12
commit 3663bbb241
4 changed files with 42 additions and 21 deletions

View File

@ -32,6 +32,8 @@ namespace Pal.Client.DependencyInjection
}
private async Task FetchFloorStatistics()
{
try
{
if (!_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "statistics:view"))
{
@ -39,8 +41,6 @@ namespace Pal.Client.DependencyInjection
return;
}
try
{
var (success, floorStatistics) = await _remoteApi.FetchStatistics();
if (success)
{

View File

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Pal.Client.Database;
@ -18,12 +19,20 @@ namespace Pal.Client.Floors.Tasks
public void Start()
{
Task.Run(() =>
{
try
{
using var scope = _serviceScopeFactory.CreateScope();
ILogger<T> logger = scope.ServiceProvider.GetRequiredService<ILogger<T>>();
using var dbContext = scope.ServiceProvider.GetRequiredService<PalClientContext>();
Run(dbContext, logger);
}
catch (Exception e)
{
DependencyInjectionContext.LoggerProvider.CreateLogger<DbTask<T>>()
.LogError(e, "Failed to run DbTask");
}
});
}

View File

@ -142,9 +142,12 @@ namespace Pal.Client
Task.Run(async () =>
{
IServiceScope rootScope;
Chat chat;
try
{
rootScope = await _rootScopeCompletionSource.Task;
chat = rootScope.ServiceProvider.GetRequiredService<Chat>();
}
catch (Exception e)
{
@ -152,17 +155,16 @@ namespace Pal.Client
return;
}
try
{
IPalacePalConfiguration configuration =
rootScope.ServiceProvider.GetRequiredService<IPalacePalConfiguration>();
Chat chat = rootScope.ServiceProvider.GetRequiredService<Chat>();
if (configuration.FirstUse && arguments != "" && arguments != "config")
{
chat.Error(Localization.Error_FirstTimeSetupRequired);
return;
}
try
{
var sp = rootScope.ServiceProvider;
switch (arguments)

View File

@ -472,7 +472,17 @@ namespace Pal.Client.Windows
CancellationTokenSource cts = new CancellationTokenSource();
_lastImportCts = cts;
Task.Run(async () => { _lastImport = await _importService.FindLast(cts.Token); }, cts.Token);
Task.Run(async () =>
{
try
{
_lastImport = await _importService.FindLast(cts.Token);
}
catch (Exception e)
{
_logger.LogError(e, "Unable to fetch last import");
}
}, cts.Token);
}
private void DoExport(string destinationPath)