当console.logging错误时,浏览器打印的输出样式与正常对象不同。如何迫使Google / Firefox打印错误类的真实对象,而不是样式化的不太有用的“错误”输出?
例如,我知道对象包含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})
})


更新后,批准答案。现在我得到了完整的错误对象。

发布于 2022-02-03 09:17:25
简单解决方案-将错误对象记录为普通对象的属性
try {
throw Error("Some error text");
}
catch( error) {
console.log( {error});
}这允许您以任何其他方式检查和展开错误对象的结构。最好在浏览器中执行,因为代码段不提供检查工具。
https://stackoverflow.com/questions/70967772
复制相似问题