Skip to content

Commit dddce01

Browse files
Hub service: fix optional config loading
1 parent 09db96b commit dddce01

File tree

1 file changed

+18
-18
lines changed
  • src/Certify.Server/Certify.Server.HubService

1 file changed

+18
-18
lines changed

src/Certify.Server/Certify.Server.HubService/Program.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@
5757
#endif
5858

5959
// load optional config but ignore errors if it doesn't exist or is invalid, otherwise service will fail to start
60-
builder.Configuration.AddJsonFile(p =>
61-
{
62-
p.Path = hubSettings;
63-
p.Optional = true;
64-
p.ReloadOnChange = true;
65-
p.OnLoadException = e =>
66-
{
67-
e.Ignore = true;
68-
69-
AddSystemStatusItem(
70-
SystemStatusCategories.HUB_API,
71-
SystemStatusKeys.HUB_API_STARTUP_CUSTOMCONFIG,
72-
title: "Hub API Service Custom Config",
73-
description: $"Error loading config file {hubSettings} - {e}",
74-
hasError: true
75-
);
76-
};
77-
});
60+
if (hubSettings != null && File.Exists(hubSettings))
61+
{
62+
try
63+
{
64+
builder.Configuration.AddJsonFile(hubSettings, optional: true, reloadOnChange: true);
65+
}
66+
catch (Exception ex)
67+
{
68+
// ignore errors loading config, we will log them later
69+
AddSystemStatusItem(
70+
SystemStatusCategories.HUB_API,
71+
SystemStatusKeys.HUB_API_STARTUP_CUSTOMCONFIG,
72+
title: "Hub API Service Custom Config",
73+
description: $"Error loading config file {hubSettings} - {ex}",
74+
hasError: true
75+
);
76+
}
77+
}
7878

7979
// if windows, run as service, otherwise run as console app
8080
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

0 commit comments

Comments
 (0)