Улучшение обработки ошибок
This commit is contained in:
@@ -83,23 +83,27 @@ class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
if (!this.inited)
|
try {
|
||||||
throw new Error('not inited');
|
if (!this.inited)
|
||||||
|
throw new Error('not inited');
|
||||||
|
|
||||||
if (await fs.pathExists(this.userConfigFile)) {
|
if (await fs.pathExists(this.userConfigFile)) {
|
||||||
const data = JSON.parse(await fs.readFile(this.userConfigFile, 'utf8'));
|
const data = JSON.parse(await fs.readFile(this.userConfigFile, 'utf8'));
|
||||||
const config = _.pick(data, propsToSave);
|
const config = _.pick(data, propsToSave);
|
||||||
|
|
||||||
this.config = config;
|
|
||||||
|
|
||||||
//сохраним конфиг, если не все атрибуты присутствуют в файле конфига
|
this.config = config;
|
||||||
for (const prop of propsToSave)
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(config, prop)) {
|
//сохраним конфиг, если не все атрибуты присутствуют в файле конфига
|
||||||
await this.save();
|
for (const prop of propsToSave)
|
||||||
break;
|
if (!Object.prototype.hasOwnProperty.call(config, prop)) {
|
||||||
}
|
await this.save();
|
||||||
} else {
|
break;
|
||||||
await this.save();
|
}
|
||||||
|
} else {
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
throw new Error(`Error while loading "${this.userConfigFile}": ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user