Wrap the code that you mentioned in padron.service with a promise like below. Now the value that is returned from the db is returned through passing it in resolve callback, and if there is some error, pass it in reject callback.
Note that in case of error, pass it to reject callback in asynchronous tasks as it will not give unexpected output in comparison to throwing the error
return new Promise((resolve, reject) => {
fb.attach(this.options, (err, db) => {
if (err) {
// throw new Error('Erro na conexión á DB');
reject('Erro na consulta ó Padrón');
}
db.query(query, params, (err, res) => {
if (err) {
// throw new Error('Erro na consulta ó Padrón');
reject('Erro na consulta ó Padrón');
}
console.log('firebird.service - Response DB ================', res);
db.detach();
// return res
resolve(res);
});
});
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…