最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Should I expect my Bugsnag plugin to capture async errors? (using BugsnagPluginReact) - Stack Overflow

programmeradmin2浏览0评论

I have a React project, and I'm using Bugsnag + BugsnagPluginReact to capture/report errors and implement an error boundary.

At the javascript entrypoint of our app, we start up Bugsnag:

import Bugsnag from "@bugsnag/js"
import BugsnagPluginReact from "@bugsnag/plugin-react"

Bugsnag.start({
  ...window.bugsnagSettings, // apiKey, releaseStage, appVersion, user
  plugins: [new BugsnagPluginReact()],
})

Then, we have an ErrorBoundaryProvider component that we wrap the root of our react code with:

import Bugsnag from "@bugsnag/js"
import React from "react"

import ErrorFallback from "./ErrorFallback"

const ErrorBoundaryProvider = ({ children }) => {
  const ErrorBoundaryWrapper = Bugsnag.getPlugin("react").createErrorBoundary(React)

  return (
    <ErrorBoundaryWrapper FallbackComponent={ErrorFallback}>
      {children}
    </ErrorBoundaryWrapper>
  )
}

export default ErrorBoundaryProvider

My question is specifically around async code. For example, say that TestComponent is a child of ErrorBoundaryProvider:

const TestComponent = () => {
  setTimeout(() => {
    throw new Error("Did this error make it to the bugsnag dashboard?")
  }, 1000)
  
  return (
    <div>Test</div>
  )
}

Should I expect the error in the setTimeout callback to show up on my bugsnag dashboard?

My understanding is that the react error boundary will NOT capture async errors like this. But I'm curious if Bugsnag will somehow pick it up anyway, as an unhandled exception.

The strange thing here is that we do see the error come through to the bugsnag dashboard, when we are in development mode, running the app locally on our machines. But, we don't see the error come through to the bugsnag dashboard when we have the app deployed to our staging/production environments.

发布评论

评论列表(0)

  1. 暂无评论