Giter Club home page Giter Club logo

fusion-plugin-error-handling's Introduction

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

fusion-plugin-error-handling's People

Contributors

renovate[bot] avatar ganemone avatar kevingrandon avatar lhorie avatar alexmsmithca avatar rtsao avatar dennisgl avatar derekjuber avatar nadiia avatar renovate-bot avatar steponas avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.