Улучшил журналирование ошибок БД

This commit is contained in:
Book Pauk
2022-07-07 16:24:59 +07:00
parent ea351ea293
commit c62bccb470

View File

@@ -2,6 +2,7 @@ const _ = require('lodash');
const utils = require('../utils'); const utils = require('../utils');
const JembaConnManager = require('../../db/JembaConnManager');//singleton const JembaConnManager = require('../../db/JembaConnManager');//singleton
const log = new (require('../AppLogger'))().log;//singleton
let instance = null; let instance = null;
@@ -20,25 +21,30 @@ class JembaReaderStorage {
} }
async doAction(act) { async doAction(act) {
if (!_.isObject(act.items)) try {
throw new Error('items is not an object'); if (!_.isObject(act.items))
throw new Error('items is not an object');
let result = {}; let result = {};
switch (act.action) { switch (act.action) {
case 'check': case 'check':
result = await this.checkItems(act.items); result = await this.checkItems(act.items);
break; break;
case 'get': case 'get':
result = await this.getItems(act.items); result = await this.getItems(act.items);
break; break;
case 'set': case 'set':
result = await this.setItems(act.items, act.force); result = await this.setItems(act.items, act.force);
break; break;
default: default:
throw new Error('Unknown action'); throw new Error('Unknown action');
}
return result;
} catch (e) {
log(LM_ERR, `JembaReaderStorage: ${e.message}`);
throw e;
} }
return result;
} }
async checkItems(items) { async checkItems(items) {