Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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
*/
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;
});
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
});
}
});
}
}
// 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
};
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() {}
});
}
}
* 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);
}
}
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)
}