Skip to content

Commit

Permalink
feat(api): adding error handling for healthCheck and setAnonymousIden…
Browse files Browse the repository at this point in the history
…tity
  • Loading branch information
mateoguzmana committed Dec 15, 2023
1 parent 95e22b1 commit 9bc6e7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
20 changes: 14 additions & 6 deletions android/src/main/java/com/zendeskunified/ZendeskUnifiedModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class ZendeskUnifiedModule(reactContext: ReactApplicationContext) :

@ReactMethod
fun healthCheck(promise: Promise) {
promise.resolve("Module compiling and working")
try {
promise.resolve("Module compiling and working")
} catch (error: Exception) {
promise.reject("healthCheck", error)
}
}

@ReactMethod
Expand All @@ -55,8 +59,6 @@ class ZendeskUnifiedModule(reactContext: ReactApplicationContext) :
val accountKey = config.getString("accountKey")

if (appId == null || clientId == null || zendeskUrl == null) {
promise.reject("ZendeskUnified", "Missing required parameters")

return
}

Expand All @@ -72,10 +74,16 @@ class ZendeskUnifiedModule(reactContext: ReactApplicationContext) :
options: ReadableMap,
promise: Promise
) {
val email = options.getString("email")
val name = options.getString("name")
try {
val email = options.getString("email")
val name = options.getString("name")

setAnonymousIdentity(email, name)
setAnonymousIdentity(email, name)

promise.resolve(true)
} catch (error: Exception) {
promise.reject("setAnonymousIdentity", error)
}
}

@ReactMethod
Expand Down
24 changes: 15 additions & 9 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ function Example() {

const loadHealthCheck = useCallback(async () => {
try {
const healthCheckResult = await zendesk?.healthCheck();
const healthCheckResult = await zendesk.healthCheck();

setHealthCheck(healthCheckResult);
} catch (error) {
console.log(error);
if (error instanceof Error) {
setHealthCheck(error.message);
}
}
}, [zendesk]);

Expand Down Expand Up @@ -113,13 +115,17 @@ function Example() {
useEffect(() => {
loadHealthCheck();

zendesk?.changeTheme('#3f2b96');
zendesk?.setAnonymousIdentity({
email: '[email protected]',
name: 'Mateo Guzmán',
});
zendesk?.setHelpCenterLocaleOverride('nl');
// zendesk.setIdentity("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9");
try {
zendesk.changeTheme('#3f2b96');
zendesk.setAnonymousIdentity({
email: '[email protected]',
name: 'Mateo Guzmán',
});
zendesk.setHelpCenterLocaleOverride('nl');
// zendesk.setIdentity("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9");
} catch (error) {
console.log(error);
}
}, [loadHealthCheck, zendesk]);

return (
Expand Down
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ export class Zendesk {
/**
* Returns whether the Zendesk module is available.
*/
public healthCheck(): string {
public async healthCheck(): Promise<string> {
return ZendeskUnified.healthCheck();
}

/**
* Sets an anonymous identity for the user using an email and/or name.
*/
public async setAnonymousIdentity(options: SetAnonymousIdentityOptions) {
await ZendeskUnified.setAnonymousIdentity(options);
public async setAnonymousIdentity(
options: SetAnonymousIdentityOptions
): Promise<boolean> {
return ZendeskUnified.setAnonymousIdentity(options);
}

/**
Expand Down

0 comments on commit 9bc6e7a

Please sign in to comment.