How to use the @bugsnag/js.getPlugin function in @bugsnag/js

To help you get started, we’ve selected a few @bugsnag/js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bugsnag / bugsnag-js / examples / react / src / index.js View on Github external
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'

import Bugsnag from '@bugsnag/js'
import bugsnagReact from '@bugsnag/plugin-react'

Bugsnag.init('YOUR_API_KEY')
Bugsnag.use(bugsnagReact, React)

const ErrorBoundary = Bugsnag.getPlugin('react')

const ErrorScreen = () =>
  <div>
    <h1><span role="img" aria-label="warning icon">⚠️</span> Error <span role="img" aria-label="warning icon">⚠️</span></h1>
    <p><strong>Uh oh, there was an error in the component tree!</strong></p>
    <p>This <code>FallbackComponent</code> prop can be used to show something useful to your users when such errors occur.</p>
  </div>

const onError = event => {
  // You can also provide an onError callback to run just on errors caught by
  // the error boundary. Maybe you want to attach some of the current state from
  // whatever model/store you're using (e.g redux)
  console.log('about to send this event', { event })
}

ReactDOM.render(
github bugsnag / bugsnag-js / examples / koa / app.js View on Github external
const Bugsnag = require('@bugsnag/js')
const Koa = require('koa')
const router = require('koa-router')
const serve = require('koa-static')
const mount = require('koa-mount')
const { readFileSync } = require('fs')

Bugsnag.init(process.env.BUGSNAG_API_KEY)
Bugsnag.use(require('@bugsnag/plugin-koa'))

const app = new Koa()
const { requestHandler, errorHandler } = Bugsnag.getPlugin('koa')

app.use(requestHandler)

app.use(mount('/static', serve(`${__dirname}/static`)))

const index = readFileSync('./views/index.html', 'utf8')

app.use(
  router()
    .get('/', (ctx, next) => {
      ctx.body = index
    })
    .post('/crash', (ctx, next) => {
      setTimeout(() => { throw new Error('Oh no!') })
      return new Promise(() => {})
    })
github bugsnag / bugsnag-js / examples / nuxtjs / modules / bugsnag / index.js View on Github external
  this.nuxt.hook('render:setupMiddleware', app => app.use(Bugsnag.getPlugin('express').requestHandler))
  this.nuxt.hook('render:errorMiddleware', app => app.use(Bugsnag.getPlugin('express').errorHandler))
github exercism / website / app / javascript / utils / react-bootloader.jsx View on Github external
releaseStage: process.env.NODE_ENV,
  plugins: [new BugsnagPluginReact()],
  enabledReleaseStages: ['production'],
  collectUserIp: false,
  onError: function (event) {
    const tag = document.querySelector('meta[name="user-id"]')

    if (!tag) {
      return true
    }

    event.setUser(tag.content)
  },
})

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

export const initReact = (mappings) => {
  document.addEventListener('turbolinks:load', () => {
    renderComponents(mappings)
    renderTooltips(mappings)
  })
}

const render = (elem, component) => {
  ReactDOM.render(
    <React.StrictMode>
      <ErrorBoundary>{component}</ErrorBoundary>
    </React.StrictMode>,
    elem,
    () => {
      setTimeout(() => {
github bugsnag / bugsnag-js / examples / nuxtjs / modules / bugsnag / index.js View on Github external
  this.nuxt.hook('render:errorMiddleware', app => app.use(Bugsnag.getPlugin('express').errorHandler))
  this.nuxt.hook('generate:routeFailed', ({ route, errors }) => {

@bugsnag/js

Universal Javascript error reporting. Automatically detect JavaScript errors in the browser and Node.js, with plugins for React, Vue, Angular, Express, Restify and Koa.

MIT
Latest version published 2 days ago

Package Health Score

89 / 100
Full package analysis