How to use the promise/setimmediate/rejection-tracking.enable function in promise

To help you get started, we’ve selected a few promise 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 unicorn-fail / dreditor / src / js / Dreditor.js View on Github external
// Global imports.
import Promise from 'promise/setimmediate/es6-extensions';
import 'promise/setimmediate/finally';
require('promise/setimmediate/rejection-tracking').enable({allRejections: true});

// Local imports.
import LocaleBase from './LocaleBase';
import Parser from './Parser';
import _ from './Utility';

export default class Dreditor extends LocaleBase {

  /**
   * @class Dreditor
   *
   * @param {Object} [options]
   *   Any additional options to pass along to the object when instantiating.
   *
   * @constructor
   */
github invertase / react-native-firebase / packages / crashlytics / lib / handlers.js View on Github external
export const setOnUnhandledPromiseRejectionHandler = once(nativeModule => {
  async function onUnhandled(id, error) {
    if (!__DEV__) {
      // TODO(salakar): Option to disable
      try {
        const stackFrames = await StackTrace.fromError(error, { offline: true });
        await nativeModule.recordErrorPromise(createNativeErrorObj(error, stackFrames, true));
      } catch (_) {
        // do nothing
      }
    }
  }
  tracking.enable({
    allRejections: true,
    onUnhandled,
  });

  return onUnhandled;
});
github getsentry / sentry-react-native / src / js / integrations / reactnativeerrorhandlers.ts View on Github external
private _handleUnhandledRejections(): void {
    if (this._options.onunhandledrejection) {
      // tslint:disable-next-line: no-implicit-dependencies
      const tracking = require("promise/setimmediate/rejection-tracking");
      tracking.disable();
      tracking.enable({
        allRejections: true,
        onHandled: () => {
          // We do nothing
        },
        onUnhandled: (id: any, error: any) => {
          getCurrentHub().captureException(error, {
            data: { id },
            originalException: error
          });
        }
      });
    }
  }
github getsentry / sentry-react-native / lib / raven-plugin.js View on Github external
// Make sure that if multiple fatals occur, we only persist the first one.
  //
  // The first error is probably the most important/interesting error, and we
  // want to crash ASAP, rather than potentially queueing up multiple errors.
  var handlingFatal = false;

  var defaultHandler =
    (ErrorUtils.getGlobalHandler && ErrorUtils.getGlobalHandler()) ||
    ErrorUtils._globalHandler;

  if (options.handlePromiseRejection) {
    // Track unhandled promise rejections
    var tracking = require('promise/setimmediate/rejection-tracking');
    tracking.disable();
    tracking.enable({
      allRejections: true,
      onUnhandled: function(id, error) {
        var captureOptions = {
          timestamp: new Date() / 1000,
          type: 'Unhandled Promise Rejection'
        };
        Raven.captureException(error, captureOptions);
      },
      onHandled: function() {}
    });
  }

  ErrorUtils.setGlobalHandler(function(error, isFatal) {
    var captureOptions = {
      timestamp: new Date() / 1000
    };
github getsentry / sentry-react-native / src / js / integrations / reactnative.ts View on Github external
private _handleUnhandledRejections(): void {
    if (this._options.onunhandledrejection) {
      const tracking = require("promise/setimmediate/rejection-tracking");
      tracking.disable();
      tracking.enable({
        allRejections: true,
        onUnhandled: (id: any, error: any) => {
          console.log(id, error);
        },
        onHandled: function() {}
      });
    }
  }
github facebook / react-native / Libraries / Promise.js View on Github external
* This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 * @flow
 */

'use strict';

const Promise = require('promise/setimmediate/es6-extensions');

require('promise/setimmediate/done');
require('promise/setimmediate/finally');

if (__DEV__) {
  require('promise/setimmediate/rejection-tracking').enable({
    allRejections: true,
    onUnhandled: (id, error = {}) => {
      let message: string;
      let stack: ?string;

      const stringValue = Object.prototype.toString.call(error);
      if (stringValue === '[object Error]') {
        message = Error.prototype.toString.call(error);
        stack = error.stack;
      } else {
        try {
          message = require('pretty-format')(error);
        } catch {
          message = typeof error === 'string' ? error : JSON.stringify(error);
        }
      }
github niunai2016 / ReactNativeAppDemo / App.js View on Github external
constructor(props) {
    super(props)
    this.timer = null
    this.state = {
      loadingCount: 0
    }

    require('promise/setimmediate/rejection-tracking').enable({
      allRejections: true,
      onUnhandled: (id, error) => {
        handleErrors(error);
      }
    })

    this._handleGlobalError = this.handleGlobalError.bind(this)
    this._handleShowLoading = this.handleShowLoading.bind(this)
    this._handleHideLoading = this.handleHideLoading.bind(this)
  }