Improve error handling
This commit is contained in:
parent
17f7dcdf12
commit
3663bbb241
@ -33,14 +33,14 @@ namespace Pal.Client.DependencyInjection
|
|||||||
|
|
||||||
private async Task FetchFloorStatistics()
|
private async Task FetchFloorStatistics()
|
||||||
{
|
{
|
||||||
if (!_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "statistics:view"))
|
|
||||||
{
|
|
||||||
_chat.Error(Localization.Command_pal_stats_CurrentFloor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "statistics:view"))
|
||||||
|
{
|
||||||
|
_chat.Error(Localization.Command_pal_stats_CurrentFloor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -19,11 +20,19 @@ namespace Pal.Client.Floors.Tasks
|
|||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
using var scope = _serviceScopeFactory.CreateScope();
|
try
|
||||||
ILogger<T> logger = scope.ServiceProvider.GetRequiredService<ILogger<T>>();
|
{
|
||||||
using var dbContext = scope.ServiceProvider.GetRequiredService<PalClientContext>();
|
using var scope = _serviceScopeFactory.CreateScope();
|
||||||
|
ILogger<T> logger = scope.ServiceProvider.GetRequiredService<ILogger<T>>();
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
|
IPalacePalConfiguration configuration =
|
||||||
|
rootScope.ServiceProvider.GetRequiredService<IPalacePalConfiguration>();
|
||||||
|
if (configuration.FirstUse && arguments != "" && arguments != "config")
|
||||||
|
{
|
||||||
|
chat.Error(Localization.Error_FirstTimeSetupRequired);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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