React Native – Error handler (2)

Bugsnag

Issue

  • createBoundary() undefined in Debug mode

Install Bugsnag

react-native/#installation

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import { ErrorView } from 'src/components'
import Bugsnag from '@bugsnag/react-native';
Bugsnag.start();
const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React);
const App = () => {
...
}
export default () => (
<ErrorBoundary FallbackComponent={ErrorView}>
<App />
</ErrorBoundary>
);
import { ErrorView } from 'src/components' import Bugsnag from '@bugsnag/react-native'; Bugsnag.start(); const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React); const App = () => { ... } export default () => ( <ErrorBoundary FallbackComponent={ErrorView}> <App /> </ErrorBoundary> );
import { ErrorView } from 'src/components'
import Bugsnag from '@bugsnag/react-native';

Bugsnag.start();

const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React);

const App = () => {
  ...
}

export default () => (
  <ErrorBoundary FallbackComponent={ErrorView}>
    <App />
  </ErrorBoundary>
);

Notify error for try/ catch

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
try {
const response = await fetchData( ... );
} catch (error) {
Bugsnag.notify(error);
}
try { const response = await fetchData( ... ); } catch (error) { Bugsnag.notify(error); }
      try {
        const response = await fetchData( ... );
      } catch (error) {
        Bugsnag.notify(error);
      }

Notify message with data and type (not for free plan(?))

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var metadata = {
from: 'moka',
to: 'french press'
}
Bugsnag.leaveBreadcrumb('Preference updated', metadata, 'state')
// types: 'navigation', 'request', 'process', 'log', 'user', 'state', 'error', 'manual'
var metadata = { from: 'moka', to: 'french press' } Bugsnag.leaveBreadcrumb('Preference updated', metadata, 'state') // types: 'navigation', 'request', 'process', 'log', 'user', 'state', 'error', 'manual'
var metadata = {
  from: 'moka',
  to: 'french press'
}
Bugsnag.leaveBreadcrumb('Preference updated', metadata, 'state')
// types: 'navigation', 'request', 'process', 'log', 'user', 'state', 'error', 'manual'

Be the first to comment

Leave a Reply

Your email address will not be published.


*