簡體   English   中英

Javascript console.log 錯誤:如何查看真正的 object 的錯誤

[英]Javascript console.log errors: how to see the real object of the Error

當 console.logging 錯誤時,瀏覽器會打印出與普通 object 不同的樣式 output。 How can you force Google / Firefox to print the real object of the Error class instead of the stylized less useful 'error' output?

例如,我知道 object 包含e.messagee.response ,例如,您永遠無法從瀏覽器日志輸出中扣除它們。

api
  .post('/post/create', formData)
  .then((res) => {
  })
  .catch((e) => {
    // doesn't print the error object
    // doesn't print the error object
    // doesn't print the error object
    console.log(e)

    // UPDATE, destructuring does print the full Error object
    // UPDATE, destructuring does print the full Error object
    // UPDATE, destructuring does print the full Error object
    console.log('full error object', {e})
  })

火狐 鉻合金

批准答案后更新。 現在我得到了完整的錯誤 object。

在此處輸入圖像描述

簡單的解決方案 - 將錯誤 object 記錄為普通 object 的屬性

try {
    throw Error("Some error text");
}
catch( error) {
    console.log( {error});
}

這允許您以與其他任何方式相同的方式檢查和擴展錯誤 object 的結構。 最好在瀏覽器中執行,因為代碼片段不提供檢查工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM