@samitouri / QOS-React-2 / commits / 8de9c6c12c

Add injection for error dialog (#9235)

Dan Abramov committed Mar 22, 2017 at 18:21 UTC 8de9c6c12c3e1ebf05b941add1d659321ea54930
1 file changed +21
src/renderers/shared/fiber/ReactFiberErrorLogger.js
+21
@@ -12,8 +12,13 @@
12
13 'use strict';
14
15 +const emptyFunction = require('fbjs/lib/emptyFunction');
16 +const invariant = require('fbjs/lib/invariant');
17 +
18 import type {CapturedError} from 'ReactFiberScheduler';
19
20 +let showDialog = emptyFunction;
21 +
22 function logCapturedError(capturedError: CapturedError): void {
23 if (__DEV__) {
24 const {
@@ -80,6 +85,22 @@ function logCapturedError(capturedError: CapturedError): void {
85 `React caught an error thrown by one of your components.\n\n${error.stack}`,
86 );
87 }
88 +
89 + showDialog(capturedError);
90 }
91
92 +exports.injection = {
93 + injectDialog(fn: (CapturedError) => void) {
94 + invariant(
95 + showDialog === emptyFunction,
96 + 'The custom dialog was already injected.',
97 + );
98 + invariant(
99 + typeof fn === 'function',
100 + 'Injected showDialog() must be a function.',
101 + );
102 + showDialog = fn;
103 + },
104 +};
105 +
106 exports.logCapturedError = logCapturedError;