增強 Node.js 中的錯誤訊息輸出關閉監聽器
P粉517475670
P粉517475670 2024-04-03 09:35:52
0
1
322

我有以下處理http請求的程式碼。

request.connection.addListener('close', function(had_error) {
   console.log(had_error);
   ...

我想列印更多錯誤訊息,但它只列印“true”。

P粉517475670
P粉517475670

全部回覆(1)
P粉662614213

使用錯誤事件來追蹤錯誤。它會傳回包含完整詳細資訊的 Error 物件。

request.connection.addListener('error', function(error) {
    console.log(error.reason|| error.message);
});

由於連線已從 v15 開始被棄用,如果您使用的是最新版本,也可以使用它

request.on('error',function(error){
    console.log(error.reason|| error.message);
});
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!