![](/img/trans.png)
[英]Cordova - How to see errors and console.log in Android Emulator
[英]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.message
和e.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.