summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorRafael Marçalo <raroma09@gmail.com>2022-10-29 23:57:43 +0100
committerRafael Marçalo <raroma09@gmail.com>2022-10-29 23:57:43 +0100
commit2cb8f9157ee1a919368d6bb0d0543124c67b5a0a (patch)
treec68c958dcadecfa49e244abf5c7fd6a8fa020f04 /server
parent5d6081e34777c8b99a3e9f2ed42a6de0732a4ff3 (diff)
Some error handling
Diffstat (limited to 'server')
-rw-r--r--server/js/config.js24
-rw-r--r--server/js/paths.js13
2 files changed, 31 insertions, 6 deletions
diff --git a/server/js/config.js b/server/js/config.js
index b1e6836..c21a246 100644
--- a/server/js/config.js
+++ b/server/js/config.js
@@ -18,17 +18,33 @@ function createConfig()
}
};
- fs.writeFileSync(configPath, JSON.stringify(defaultConfig), 'utf-8');
+ try
+ {
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig), 'utf-8');
+ }
+
+ catch (err)
+ {
+ console.log(err);
+ }
}
function loadConfig(configPath)
{
- if (!fs.existsSync(configPath))
+ try
{
- createConfig(configPath, defaultConfig);
+ if (!fs.existsSync(configPath))
+ {
+ createConfig(configPath, defaultConfig);
+ }
+
+ this.loadedConfig = JSON.parse(fs.readFileSync(configPath));
}
- this.loadedConfig = JSON.parse(fs.readFileSync(configPath));
+ catch (err)
+ {
+ console.log(err);
+ }
}
module.exports = { loadConfig, defaultConfigPath, loadedConfig }; \ No newline at end of file
diff --git a/server/js/paths.js b/server/js/paths.js
index 3bf6824..003d9c0 100644
--- a/server/js/paths.js
+++ b/server/js/paths.js
@@ -6,10 +6,19 @@ const os = require('os');
function ensureFolder(folder)
{
- if (!fs.existsSync(folder))
+ try
{
- fs.mkdirSync(folder, { recursive: true });
+ if (!fs.existsSync(folder))
+ {
+ fs.mkdirSync(folder, { recursive: true });
+ }
}
+
+ catch (err)
+ {
+ console.log(err);
+ }
+
return folder;
}