1- import { ErrorHandlerCallback , Platform } from 'react-native' ;
1+ import { Platform } from 'react-native' ;
22import parseErrorStackLib , {
33 ExtendedError ,
44 StackFrame ,
@@ -67,12 +67,16 @@ export const captureJsErrors = () => {
6767
6868 const originalErrorHandler = ErrorUtils . getGlobalHandler ( ) ;
6969
70- const instabugErrorHandler : ErrorHandlerCallback = ( err ) => {
71- sendCrashReport ( err , NativeCrashReporting . sendJSCrash ) ;
70+ const instabugErrorHandler = ( err : any , _isFatal ?: boolean ) : Promise < void > => {
71+ return sendCrashReport ( err , NativeCrashReporting . sendJSCrash ) ;
7272 } ;
7373
74- ErrorUtils . setGlobalHandler ( ( err , isFatal ) => {
75- instabugErrorHandler ( err , isFatal ) ;
74+ ErrorUtils . setGlobalHandler ( async ( err , isFatal ) => {
75+ console . log ( 'IBG-RN: Captured a JavaScript error' , err ) ;
76+
77+ await instabugErrorHandler ( err , isFatal ) ;
78+
79+ console . log ( 'IBG-RN: Reported the JavaScript error to Instabug' , err ) ;
7680
7781 if ( process . env . JEST_WORKER_ID ) {
7882 return ;
@@ -86,6 +90,8 @@ export const captureJsErrors = () => {
8690 originalErrorHandler ( err , isFatal ) ;
8791 }
8892 } ) ;
93+
94+ console . log ( 'IBG-RN: Global error handler is now set.' ) ;
8995} ;
9096
9197export const stringifyIfNotString = ( input : unknown ) => {
@@ -104,9 +110,9 @@ export const stringifyIfNotString = (input: unknown) => {
104110 * `sendCrashReport(error, NativeCrashReporting.sendJSCrash);`
105111 *
106112 */
107- export function sendCrashReport (
113+ export async function sendCrashReport (
108114 error : ExtendedError ,
109- remoteSenderCallback : ( json : CrashData | string ) => void ,
115+ remoteSenderCallback : ( json : CrashData | string ) => Promise < void > ,
110116) {
111117 const jsStackTrace = getStackTrace ( error ) ;
112118
@@ -120,10 +126,10 @@ export function sendCrashReport(
120126 } ;
121127
122128 if ( Platform . OS === 'android' ) {
123- remoteSenderCallback ( JSON . stringify ( jsonObject ) ) ;
124- } else {
125- remoteSenderCallback ( jsonObject ) ;
129+ return remoteSenderCallback ( JSON . stringify ( jsonObject ) ) ;
126130 }
131+
132+ return remoteSenderCallback ( jsonObject ) ;
127133}
128134
129135export default {
0 commit comments