-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
6.19.7
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
- use
ErrorBoundary
in React project:
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
// ......
componentDidCatch(error: Error, errorInfo: any) {
if (window.Sentry) {
window.Sentry.withScope(scope => {
Object.keys(errorInfo).forEach(key => {
scope.setExtra(key, errorInfo[key])
})
window.Sentry.captureException(error)
})
}
}
// ......
}
export default ErrorBoundary
- throw an error in the example component:
export const Example = () => {
useEffect(() => {
throw new Error('this is the error')
})
return <div>example</div>
}
Expected Result
ErrorBoundary
catch the error and report it to the sentry platform with window.Sentry.captureException
Actual Result
window.Sentry.captureException
didn't work and none of sentry requests sent. But when I added another window.Sentry.captureException
outside the window.Sentry.withScope
, it worked. Both of the captureException
be executed.
componentDidCatch(error: Error, errorInfo: any) {
if (window.Sentry) {
window.Sentry.withScope(scope => {
Object.keys(errorInfo).forEach(key => {
scope.setExtra(key, errorInfo[key])
})
window.Sentry.captureException(error)
})
window.Sentry.captureException(new Error('error outside'))
}
}
Metadata
Metadata
Assignees
Projects
Status
Waiting for: Product Owner