From 9175734189cfc8294357e1671ea367096b7023c6 Mon Sep 17 00:00:00 2001 From: RainOrigami Date: Mon, 2 Oct 2023 17:56:26 +0200 Subject: [PATCH] Do not crash the API if config fails to save --- BattleBitAPIRunner/Program.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/BattleBitAPIRunner/Program.cs b/BattleBitAPIRunner/Program.cs index 824826e..4ca45ed 100644 --- a/BattleBitAPIRunner/Program.cs +++ b/BattleBitAPIRunner/Program.cs @@ -547,10 +547,17 @@ private void ModuleConfiguration_OnSavingRequest(object? sender, BattleBitModule return; // nothing to save } - File.WriteAllText(filePath, JsonSerializer.Serialize(configurationValue, configurationValue.GetType(), new JsonSerializerOptions() + try { - WriteIndented = true - })); + File.WriteAllText(filePath, JsonSerializer.Serialize(configurationValue, configurationValue.GetType(), new JsonSerializerOptions() + { + WriteIndented = true + })); + } + catch (Exception ex) + { + this.logger.Error($"Failed to save configuration {property.Name} for module {module.GetType().Name}.", ex); + } } private void ModuleConfiguration_OnLoadingRequest(object? sender, BattleBitModule module, PropertyInfo property, string serverName)