From d2001a8fc2ac695f3ad37dbec0be2e092c7f139f Mon Sep 17 00:00:00 2001 From: Rammohan Akula Date: Wed, 4 Sep 2024 13:29:33 -0700 Subject: [PATCH] Update eventEmitter.ts Catch 'unable to auto initialize connection', add optional error callback. --- src/eventEmitter.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/eventEmitter.ts b/src/eventEmitter.ts index 40077d5d8..7f6bc1771 100644 --- a/src/eventEmitter.ts +++ b/src/eventEmitter.ts @@ -46,6 +46,7 @@ const App = () => { */ export const purchaseUpdatedListener = ( listener: (event: Purchase) => void, + errorCallback?: (error: unknown) => void, ) => { const eventEmitter = new NativeEventEmitter(getNativeModule()); const proxyListener = isIosStorekit2() @@ -59,7 +60,13 @@ export const purchaseUpdatedListener = ( ); if (isAndroid) { - getAndroidModule().startListening(); + getAndroidModule().startListening().catch((error: unknown) => { + if (errorCallback) { + errorCallback(error); + } else { + throw error; + } + }); } return emitterSubscription;