Skip to content

Commit d774563

Browse files
committed
Adding a try catch to handle the cases, where we fail to read the current default local.
1 parent eb4be01 commit d774563

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

eFormAPI/eFormAPI/Controllers/SettingsController.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ public OperationResult ConnectionStringExist()
4242
[Route("api/settings/default-locale")]
4343
public OperationDataResult<string> GetDefaultLocale()
4444
{
45-
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
46-
var section = (AppSettingsSection)configuration.GetSection("appSettings");
47-
var locale = section.Settings["general:defaultLocale"].Value;
48-
if (locale == null)
45+
try
46+
{
47+
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
48+
var section = (AppSettingsSection)configuration.GetSection("appSettings");
49+
var locale = section.Settings["general:defaultLocale"].Value;
50+
if (locale == null)
51+
{
52+
return new OperationDataResult<string>(true, "en-US");
53+
}
54+
return new OperationDataResult<string>(true, model: locale);
55+
} catch
4956
{
57+
// We do this if any of the above fail for some reason, then we set it to default en-US
5058
return new OperationDataResult<string>(true, "en-US");
5159
}
52-
return new OperationDataResult<string>(true, model: locale);
60+
5361
}
5462

5563

0 commit comments

Comments
 (0)