ViB*_*Cci 11 javascript console.log
当 console.logging 出错时,浏览器会打印与普通对象不同样式的输出。如何强制 Google / Firefox 打印 Error 类的真实对象,而不是程式化的不太有用的“错误”输出?
例如,我知道该对象包含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})
})
Run Code Online (Sandbox Code Playgroud)
批准答案后更新。现在我得到了完整的错误对象。
tra*_*r53 12
简单的解决方案 - 将错误对象记录为普通对象的属性
try {
throw Error("Some error text");
}
catch( error) {
console.log( {error});
}
Run Code Online (Sandbox Code Playgroud)
这允许您以与任何其他对象相同的方式检查和扩展错误对象的结构。最好在浏览器中执行,因为代码片段不提供检查工具。
| 归档时间: |
|
| 查看次数: |
5652 次 |
| 最近记录: |