fusion-plugin-error-handling
TypeScript icon, indicating that this package has built-in type declarations

2.5.2 • Public • Published

fusion-plugin-error-handling

Build status

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


Table of contents


Installation

yarn add fusion-plugin-error-handling

Usage

// src/monitoring.js
import {createPlugin} from 'fusion-core';

export default __NODE__ && createPlugin({
  provides() {
    return (e, captureType) => {
        if (captureType === 'browser') {
          const {message, source, line, col, error} = e;
          console.log({message, source, line, col, error});
        } else if (captureType === 'server') {
          console.log('UNCAUGHT EXCEPTION', e);
        } else if (captureType === 'request') {
          console.log('REQUEST ERROR');
        }
      }
    }
  }
});

Normally, instead of using console, you would consume errors via something like Kafka or at least use a production logger (such as fusion-plugin-universal-logger) in conjunction with a logging service such as LogEntries or Papertrail.


Setup

// src/main.js
import React from 'react';
import App from 'fusion-react';
import ErrorHandling, {ErrorHandlerToken} from 'fusion-plugin-error-handling';
import log from './monitoring';

export default () => {
  const app = new App(<div />);
  if (__NODE__) {
    app.register(ErrorHandlerToken, log);
    app.register(ErrorHandling);
  }
  return app;
};

API

Registration API

ErrorHandling
import ErrorHandling from 'fusion-plugin-error-handling';

The plugin. Typically doesn't need to be associated with a token.

Dependencies

ErrorHandlerToken
import {ErrorHandlerToken} from 'fusion-plugin-error-handling';

A function to be called when an error is reported.

Types
type ErrorHandler = (e: Error, captureType: string) => Promise

If the error is a global uncaught exception or unhandled rejection, the process exits when the returned Promise resolves/rejects.

  • e: Error - The error that was reported
  • captureType: string - Either 'browser', 'uncaught' or 'request'.
  • returns Promise

Dependencies (1)

Dev Dependencies (14)

Package Sidebar

Install

npm i fusion-plugin-error-handling

Weekly Downloads

9

Version

2.5.2

License

MIT

Unpacked Size

205 kB

Total Files

39

Last publish

Collaborators

  • fusion-ci