diff --git a/Pal.Client/DependencyInjection/StatisticsService.cs b/Pal.Client/DependencyInjection/StatisticsService.cs index 9b9a029..5b461f6 100644 --- a/Pal.Client/DependencyInjection/StatisticsService.cs +++ b/Pal.Client/DependencyInjection/StatisticsService.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Dalamud.Game.Gui; using Grpc.Core; +using Microsoft.Extensions.Logging; using Pal.Client.Configuration; using Pal.Client.Extensions; using Pal.Client.Net; @@ -13,14 +14,20 @@ namespace Pal.Client.DependencyInjection internal sealed class StatisticsService { private readonly IPalacePalConfiguration _configuration; + private readonly ILogger _logger; private readonly RemoteApi _remoteApi; private readonly StatisticsWindow _statisticsWindow; private readonly Chat _chat; - public StatisticsService(IPalacePalConfiguration configuration, RemoteApi remoteApi, - StatisticsWindow statisticsWindow, Chat chat) + public StatisticsService( + IPalacePalConfiguration configuration, + ILogger logger, + RemoteApi remoteApi, + StatisticsWindow statisticsWindow, + Chat chat) { _configuration = configuration; + _logger = logger; _remoteApi = remoteApi; _statisticsWindow = statisticsWindow; _chat = chat; @@ -54,11 +61,14 @@ namespace Pal.Client.DependencyInjection } catch (RpcException e) when (e.StatusCode == StatusCode.PermissionDenied) { + _logger.LogWarning(e, "Access denied while fetching floor statistics"); _chat.Error(Localization.Command_pal_stats_CurrentFloor); } catch (Exception e) { - _chat.Error(e.ToString()); + _logger.LogError(e, "Could not fetch floor statistics"); + _chat.Error(string.Format(Localization.Error_CommandFailed, + $"{e.GetType()} - {e.Message}")); } } } diff --git a/Pal.Client/Plugin.cs b/Pal.Client/Plugin.cs index 312f23f..aefe7b1 100644 --- a/Pal.Client/Plugin.cs +++ b/Pal.Client/Plugin.cs @@ -187,7 +187,8 @@ namespace Pal.Client { _logger.LogError(e, "Could not execute command '{Command}' with arguments '{Arguments}'", command, arguments); - chat.Error(e.ToString()); + chat.Error(string.Format(Localization.Error_CommandFailed, + $"{e.GetType()} - {e.Message}")); } }); } diff --git a/Pal.Client/Properties/Localization.Designer.cs b/Pal.Client/Properties/Localization.Designer.cs index 2c95215..5811bd6 100644 --- a/Pal.Client/Properties/Localization.Designer.cs +++ b/Pal.Client/Properties/Localization.Designer.cs @@ -619,6 +619,15 @@ namespace Pal.Client.Properties { } } + /// + /// Looks up a localized string similar to Command could not be executed: {0}. + /// + internal static string Error_CommandFailed { + get { + return ResourceManager.GetString("Error_CommandFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Please finish the initial setup first.. /// diff --git a/Pal.Client/Properties/Localization.resx b/Pal.Client/Properties/Localization.resx index ddac1c3..25c4a9c 100644 --- a/Pal.Client/Properties/Localization.resx +++ b/Pal.Client/Properties/Localization.resx @@ -48,6 +48,7 @@ Plugin could not be loaded: {0} + Shown when the plugin fails to load, with the placeholder filled with the exception message. Please install this plugin from the official repository at {0} to continue using it. @@ -69,6 +70,10 @@ Unable to fetch statistics. Shown when /pal stats produces a server-side error, and the statistics window can't be loaded. + + Command could not be executed: {0} + Shown when '/pal ...' fails, with the placeholder filled with the exception message. +