Skip to content

Commit 04f2e3f

Browse files
authored
Prevent app creash if CafeBazaar is not installed
When CafeBazaar is not installed, the app using the lib will crash. Fixed the bug using a try and catch and rejecting the promise with `E_SETUP_DISCONNECT: there no connection to cafe bazaar` error.
1 parent 1567d25 commit 04f2e3f

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

android/app/src/main/java/com/contoriel/cafebazaar/CafeBazaar.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,32 @@ public void open(final Promise promise) {
8888
// enable debug logging (for a production application, you should set this to false).
8989
mHelper.enableDebugLogging(false);
9090

91+
try {
9192
// Start setup. This is asynchronous and the specified listener
9293
// will be called once setup completes.
93-
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
94-
public void onIabSetupFinished(IabResult result) {
95-
96-
if (result.isSuccess()) {
97-
promise.resolve(gson.toJson(result));
94+
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
95+
public void onIabSetupFinished(IabResult result) {
96+
97+
if (result.isSuccess()) {
98+
promise.resolve(gson.toJson(result));
99+
}
100+
else{
101+
// Have we been disposed of in the meantime? If so, quit.
102+
if (mHelper == null) {
103+
promise.reject(E_SETUP_DISCONNECT,"there no connection to cafe bazaar!");
104+
}
105+
else{
106+
// Oh noes, there was a problem.
107+
promise.reject(E_SETUP_ERROR,"There is a problem in cafe bazaar setup");
108+
}
109+
}
98110
}
99-
else{
100-
// Have we been disposed of in the meantime? If so, quit.
101-
if (mHelper == null) {
102-
promise.reject(E_SETUP_DISCONNECT,"there no connection to cafe bazaar!");
103-
}
104-
else{
105-
// Oh noes, there was a problem.
106-
promise.reject(E_SETUP_ERROR,"There is a problem in cafe bazaar setup");
107-
}
108-
}
109-
}
110-
});
111+
});
112+
113+
} catch(Exception excep) {
114+
promise.reject(E_SETUP_DISCONNECT,"there no connection to cafe bazaar!");
115+
Log.e("BazarOpenError", "Could not open bazar", excep);
116+
}
111117
}
112118

113119

0 commit comments

Comments
 (0)