From e865070f233ab736e998a04c4c1dff894fe2d4c1 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 21 Oct 2022 13:50:55 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config/index.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/server/config/index.js b/server/config/index.js index ee0aef5..cf98140 100644 --- a/server/config/index.js +++ b/server/config/index.js @@ -83,23 +83,27 @@ class ConfigManager { } async load() { - if (!this.inited) - throw new Error('not inited'); + try { + if (!this.inited) + throw new Error('not inited'); - if (await fs.pathExists(this.userConfigFile)) { - const data = JSON.parse(await fs.readFile(this.userConfigFile, 'utf8')); - const config = _.pick(data, propsToSave); - - this.config = config; + if (await fs.pathExists(this.userConfigFile)) { + const data = JSON.parse(await fs.readFile(this.userConfigFile, 'utf8')); + const config = _.pick(data, propsToSave); - //сохраним конфиг, если не все атрибуты присутствуют в файле конфига - for (const prop of propsToSave) - if (!Object.prototype.hasOwnProperty.call(config, prop)) { - await this.save(); - break; - } - } else { - await this.save(); + this.config = config; + + //сохраним конфиг, если не все атрибуты присутствуют в файле конфига + for (const prop of propsToSave) + if (!Object.prototype.hasOwnProperty.call(config, prop)) { + await this.save(); + break; + } + } else { + await this.save(); + } + } catch(e) { + throw new Error(`Error while loading "${this.userConfigFile}": ${e.message}`); } }