From 2cb8f9157ee1a919368d6bb0d0543124c67b5a0a Mon Sep 17 00:00:00 2001 From: Rafael Marçalo Date: Sat, 29 Oct 2022 23:57:43 +0100 Subject: Some error handling --- server/js/config.js | 24 ++++++++++++++++++++---- server/js/paths.js | 13 +++++++++++-- 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; } -- cgit v1.2.3