Bugsnag-js: Example of FallBackComponent with ErrorBoundry

Created on 19 Dec 2018  路  6Comments  路  Source: bugsnag/bugsnag-js

Hi

I see that you can add some sort of fallback component in Error Boundry but there is no example code that I can see.

So I am not sure how my component should look like and how it hooks up to

All 6 comments

This is quite a useless example as it doesn't show any useful information to the user, such as an issue ID

Hi Tom

I saw you also reached out to Bugsnag support on that point so please see my full response there.

There isn't a Bugsnag issue ID available in the client but you could generate your own issue ID and supply as custom metadata in the error report to allow filtering by it in the dashboard.

How about an example showing the error?

Hey @simkessy, what do you mean by showing the error? A way to link to the error in Bugsnag?

When bugsnag-js sends the report, the ID for the error is generated by Bugsnag on server-side, so the library doesn't have access to that. If you want to display an issue ID to the user and have that same issue ID shown in Bugsnag, you'll want to generate your own issue ID and supply that in the error report as an additional metaData field by using a beforeSend callback.

You can then add a custom filter on your new metaData field to filter for that issue ID in the dashboard, and display the generated issue ID inside of your FallbackComponent as an argument input to the component:

const ErrorReturn = (issueID) => {
   return <div> 
     <h1>鈿狅笍 Error 鈿狅笍</h1> 
     <p><strong>Uh oh, there was an error in the component tree!</strong></p> 
     <p>Issue ID <code>{issueID}</code> reported to Bugsnag</p> 
   </div>
}
const ErrorScreen = ({ error }) => {
  return (
    <Box marginLeft={-1} marginRight={-1}>
      <Layer>
        <Modal accessibilityModalLabel="Error" heading="Error" size="sm">
          <Box padding={2}>
            <Text>{error.message}</Text>
          </Box>
        </Modal>
      </Layer>
    </Box>
  );
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

foxyblocks picture foxyblocks  路  5Comments

mattimatti picture mattimatti  路  4Comments

lifeiscontent picture lifeiscontent  路  6Comments

livthomas picture livthomas  路  4Comments

bathos picture bathos  路  6Comments