如何更改Sentry中使用的JavaScript错误对象的名称或消息?
我有一个用代码捕获的JavaScript错误对象。它具有我想登录后端的名称,消息,堆栈等。我正在使用哨兵。但是在登录之前,我想更改错误的名称或消息。
最好的方法是什么? 我尝试创建一个新的错误,并将原始错误添加为原因
,但这与Sentry不起作用。它只是将传递的错误记录为新错误的原因。
new Error('Additional error message', { cause: originalError });
我需要错误的其余属性保持不变,只需更改名称或消息即可。
I have a JavaScript error object that I have caught in code. It has a name, message, stack etc that I want to log at the backend. I am using sentry for that. But before logging I want to change the name or the message of the error.
What will be the best way to do it?
I tried creating a new error and adding the original error as cause
, but that did not work with sentry. It just logs the error passed as the cause of the new error.
new Error('Additional error message', { cause: originalError });
I need the rest of the properties of the error to remain the same, just need to change the name or message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对此有一些可读性的错误:
当您捕获异常时,将TransActionName添加到
scope
。您还可以在
beforesend
方法中增强事件I've made errors a bit readable with this:
when you capture exception, add transactionName to
scope
.you can also enhance event in
beforeSend
method您可以做的一件超级有用的事情实际上是创建自己的自定义错误类型。这可以通过简单地使用扩展错误构造函数的类来完成,例如:
A super helpful thing you can do to accomplish this is actually create your own custom error types. This can be done by simply using a class that extends the Error constructor, like so:
除了@anastasia plaskevich的答案外,您似乎还可以更改这样的错误类型:
In addition to @Anastasia Plaskevich's answer, It appears that you can also change the Error type like this:
Then you'll see something like this: