Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Add Token dependencies to readme #70

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@

[![Build status](https://badge.buildkite.com/1a76dbe95f76cd888a286290c365fabd54fcc62edb3895aa5d.svg?branch=master)](https://buildkite.com/uberopensource/fusion-plugin-error-handling)

Collects browser errors, server request errors, and uncaught exceptions, and provides an api for handling them.
Collects browser errors, server request errors, and uncaught exceptions, and provides an API for handling them.

---

### Installation

```sh
yarn add fusion-plugin-error-handling
```

---

### Example

```js
// src/main.js
import React from 'react';
import App from 'fusion-react';
import Monitoring from './monitoring';
import registerMonitoring from './monitoring';

export default () => {
const app = new App(<div></div>);
app.plugin(Monitoring);
registerMonitoring(app);
return app;
}

// src/monitoring.js
import ErrorHandling from 'fusion-plugin-error-handling';
import ErrorHandlingPlugin, {ErrorHandlerToken} from 'fusion-plugin-error-handling';

export default ({}) => {
export default (app) => {
if (__NODE__) {
const log = (e, captureType) => {
if (captureType === 'browser') {
Expand All @@ -39,14 +43,25 @@ export default ({}) => {
console.log('REQUEST ERROR');
}
}
return ErrorHandling({onError: log});
// Register dependencies
app.register(ErrorHandlerToken, log);
app.register(ErrorHandlingPlugin);
}
}
```

---

### API

`ErrorHandling({onError, CsrfProtection})`
#### Dependency registration
```js
import {ErrorHandlerToken} from 'fusion-plugin-error-handling';

__NODE__ && app.register(ErrorHandlerToken, /*some error handler*/);
```

- `onError: (e: Error, captureType: 'browser' | 'uncaught' | 'request') => Promise` - Required. A function that gets called on server errors. If the error is a global uncaught exception or unhandled rejection, the process exits when the returned Promise resolves/rejects.
- `CsrfProtection` - Optional. Pass your [`fusion-plugin-csrf-protection`](https://github.com/fusionjs/fusion-plugin-csrf-protection) plugin to this package if CSRF protection is enabled, in order to allow errors to be logged without needing a CSRF token.
##### Required dependencies
Name | Type | Description
-|-|-
`ErrorHandlerToken` | `(e: Error, captureType: 'browser' or 'uncaught' or 'request') => Promise` | A function that gets called on server errors. If the error is a global uncaught exception or unhandled rejection, the process exits when the returned Promise resolves/rejects. Server-side only.