Improve error handling
This commit is contained in:
parent
17f7dcdf12
commit
53aa8208fe
@ -32,6 +32,8 @@ namespace Pal.Client.DependencyInjection
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task FetchFloorStatistics()
|
private async Task FetchFloorStatistics()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "statistics:view"))
|
if (!_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "statistics:view"))
|
||||||
{
|
{
|
||||||
@ -39,8 +41,6 @@ namespace Pal.Client.DependencyInjection
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var (success, floorStatistics) = await _remoteApi.FetchStatistics();
|
var (success, floorStatistics) = await _remoteApi.FetchStatistics();
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Pal.Client.Database;
|
using Pal.Client.Database;
|
||||||
@ -18,12 +19,20 @@ namespace Pal.Client.Floors.Tasks
|
|||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using var scope = _serviceScopeFactory.CreateScope();
|
using var scope = _serviceScopeFactory.CreateScope();
|
||||||
ILogger<T> logger = scope.ServiceProvider.GetRequiredService<ILogger<T>>();
|
ILogger<T> logger = scope.ServiceProvider.GetRequiredService<ILogger<T>>();
|
||||||
using var dbContext = scope.ServiceProvider.GetRequiredService<PalClientContext>();
|
using var dbContext = scope.ServiceProvider.GetRequiredService<PalClientContext>();
|
||||||
|
|
||||||
Run(dbContext, logger);
|
Run(dbContext, logger);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DependencyInjectionContext.LoggerProvider.CreateLogger<DbTask<T>>()
|
||||||
|
.LogError(e, "Failed to run DbTask");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,9 +142,12 @@ namespace Pal.Client
|
|||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
IServiceScope rootScope;
|
IServiceScope rootScope;
|
||||||
|
Chat chat;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rootScope = await _rootScopeCompletionSource.Task;
|
rootScope = await _rootScopeCompletionSource.Task;
|
||||||
|
chat = rootScope.ServiceProvider.GetRequiredService<Chat>();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -152,17 +155,16 @@ namespace Pal.Client
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
IPalacePalConfiguration configuration =
|
IPalacePalConfiguration configuration =
|
||||||
rootScope.ServiceProvider.GetRequiredService<IPalacePalConfiguration>();
|
rootScope.ServiceProvider.GetRequiredService<IPalacePalConfiguration>();
|
||||||
Chat chat = rootScope.ServiceProvider.GetRequiredService<Chat>();
|
|
||||||
if (configuration.FirstUse && arguments != "" && arguments != "config")
|
if (configuration.FirstUse && arguments != "" && arguments != "config")
|
||||||
{
|
{
|
||||||
chat.Error(Localization.Error_FirstTimeSetupRequired);
|
chat.Error(Localization.Error_FirstTimeSetupRequired);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var sp = rootScope.ServiceProvider;
|
var sp = rootScope.ServiceProvider;
|
||||||
|
|
||||||
switch (arguments)
|
switch (arguments)
|
||||||
|
@ -472,7 +472,17 @@ namespace Pal.Client.Windows
|
|||||||
CancellationTokenSource cts = new CancellationTokenSource();
|
CancellationTokenSource cts = new CancellationTokenSource();
|
||||||
_lastImportCts = cts;
|
_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)
|
private void DoExport(string destinationPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user