Catch exception in save method for json class (#5950)

* Catch exception in save method for json class

* Update error message

* Correct error logging format

* Catch IO exception
This commit is contained in:
Divyansh Srivastava
2020-08-18 10:50:16 -07:00
committed by GitHub
parent 13d61bd866
commit cedc4f710e

View File

@@ -118,10 +118,17 @@ namespace Wox.Infrastructure.Storage
public void Save()
{
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
File.WriteAllText(FilePath, serialized);
_storageHelper.Close();
Log.Info($"|JsonStorage.Save|Saving cached data| <{FilePath}>");
try
{
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
File.WriteAllText(FilePath, serialized);
_storageHelper.Close();
Log.Info($"|JsonStorage.Save|Saving cached data| <{FilePath}>");
}
catch (IOException e)
{
Log.Error($"|JsonStorage.Save|Error in saving data| <{FilePath}>", e.Message);
}
}
}
}