react-error-reporter
Report catched errors using React components. Report them to sentry, etc...
Last updated 3 years ago by michalkvasnicak .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-error-reporter 
SYNC missed versions from official npm registry.

react-error-reporter

npm CircleCI

gzip size size module formats: umd, cjs, esm

Simple error reporting using React components.

npm install --save react-error-reporter

Example

import ErrorReporter, { CaptureException } from 'react-error-reporter';

<ErrorReporter captureException={(error, ...args) => console.error(error, ...args)}>
  <CaptureException error={new Error('Test Error')} extra={[{ contextToError: true }]} />
</ErrorReporter>

Advanced Example

import GraphQL from 'react-apollo-graphql';
import ErrorReporter, { CaptureException } from 'react-error-reporter';

<ErrorReporter captureException={console.error}>
  <GraphQL queries={{ projects: ... }} render={(queries) => {
    if (queries.projects.error) {
      return <CaptureException error={queries.projects.error} />;
    }

    if (queries.projects.loading) {
      return <Loading />;
    }

    return queries.projects.data.projects.map(
      project => <div key={project.id}>{project.title}</div>
    );
  }} />
</ErrorReporter>

API

<ErrorReporter />

Provides captureException to the context. Your app must be wrapped using this component.

type Props = {
  captureException(error: Error, ...args: any): void,
}

<CaptureException />

Captures exception, passing error and extra to captureException handler. This components renders null.

Captures exception on componentWillMount() if the error prop is set and componentDidUpdate() if the error props has changed and is set.

type Props = {
  // optional error
  // will be passed to captureException() as the first argument.
  error: ?Error,

  // passes extra data to captureException()
  // each item in array is passed to captureException(error, item0, item1) as respective argument after the error
  // for example extra={[{ test: 1 }, { test: 2 }]}
  // will call captureException(error, { test: 1 }, { test: 2 })
  extra: ?Array<any>,
}

Current Tags

  • 1.0.1                                ...           latest (3 years ago)

3 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 1.0.0-rc.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |