Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 连接超时时Nodejs mssql未处理承诺_Javascript_Node.js_Sql Server - Fatal编程技术网

Javascript 连接超时时Nodejs mssql未处理承诺

Javascript 连接超时时Nodejs mssql未处理承诺,javascript,node.js,sql-server,Javascript,Node.js,Sql Server,情况很简单:我使用NPMSSQL包使用池方法建立数据库连接。要初始化池,我只需执行以下操作: const poolPromise = new sql.ConnectionPool(config) .connect() .then(pool => { console.log('<---- POOL CONNECTED TO MSSQL ---->') return pool; }, error => { console.log('<

情况很简单:我使用NPMSSQL包使用池方法建立数据库连接。要初始化池,我只需执行以下操作:

const poolPromise = new sql.ConnectionPool(config)
  .connect()
  .then(pool => {
    console.log('<---- POOL CONNECTED TO MSSQL ---->')
    return pool;
  }, error => {
    console.log('<---- DATABASE IS DOWN ---->')
  }).catch(err => {
    // HERE I LOG THE ERROR SOMEWHERE ELSE
    console.log('Database Connection Failed! Bad Config: ', err)
  });

module.exports = {
  sql, poolPromise
}
constpoolpromise=newsql.ConnectionPool(配置)
.connect()
。然后(池=>{
console.log(“”)
回流池;
},错误=>{
console.log(“”)
}).catch(错误=>{
//在这里,我将错误记录在其他地方
console.log('数据库连接失败!错误配置:',错误)
});
module.exports={
sql,poolPromise
}
现在,问题是数据库服务器现在有点不稳定。有时它会下降一段时间。这是DB人员必须解决的问题,但我希望能够通知UI DB在某个点上出现故障。但是,引发的异常不会被那里的catch块捕获。它只在nodejs控制台中写入以下内容:


(节点:2962)未经处理的PromiserEjectionWarning:ConnectionError:未能连接到:1433-连接EtimeOut:1433
在Connection.tedious.once.err(/project/node_modules/mssql/lib/tedious.js:239:17)
在Object.onceWrapper(events.js:277:13)
在Connection.emit(events.js:189:13)
位于Connection.EventEmitter.emit(domain.js:441:20)
位于Connection.socketError(/project/node_modules/tedious/lib/Connection.js:1024:14)
at/project/node_modules/tedious/lib/connection.js:868:25
位于Socket.onError(/project/node_modules/tedious/lib/connector.js:49:9)
在Socket.emit(events.js:189:13)
位于Socket.EventEmitter.emit(domain.js:441:20)
在发射时出错(内部/streams/destroy.js:82:8)
(节点:2962)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:2)
(节点:2962)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。
----
你们知道如何捕捉这个特殊事件并正确记录吗

(node:2962) UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to <serverIP>:1433 - connect ETIMEDOUT <severIP>:1433
    at Connection.tedious.once.err (/project/node_modules/mssql/lib/tedious.js:239:17)
    at Object.onceWrapper (events.js:277:13)
    at Connection.emit (events.js:189:13)
    at Connection.EventEmitter.emit (domain.js:441:20)
    at Connection.socketError (/project/node_modules/tedious/lib/connection.js:1024:14)
    at /project/node_modules/tedious/lib/connection.js:868:25
    at Socket.onError (/project/node_modules/tedious/lib/connector.js:49:9)
    at Socket.emit (events.js:189:13)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at emitErrorNT (internal/streams/destroy.js:82:8)
(node:2962) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:2962) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


----