【发布时间】:2020-06-28 02:47:01
【问题描述】:
我有这个功能。查询成功时效果很好,但是当我收到错误时,我需要返回错误响应。我已经看到了一些使用 res.json 的示例,但 res in 在 catch 中不可用。如何向此 api 的用户返回错误响应。
pg.Client = config;
client = await pool.connect();
pool.connect()
.then(client => {
return client.query(query)
.then(res => {
client.release();
return res.rows;
})
.catch(e => {
client.release();
console.log(e.stack);
})
}).finally(() => client.close);
【问题讨论】:
标签: javascript node.js postgresql