Skip to content

Conversation

@cacheung
Copy link
Contributor

Add promise checking for error case

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Add promise checking for error case
Identity.getExperienceCloudId(new AdobeCallbackWithError<String>() {
@Override
public void fail(AdobeError error) {
promise.reject("AdobeError", error.getErrorName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also provide an extension name when calling reject in Java code.

promise.reject(getName(), FAILED_TO_CONVERT_EVENT_MESSAGE, new Error(FAILED_TO_CONVERT_EVENT_MESSAGE));

Copy link
Contributor Author

@cacheung cacheung Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote it, the sample output for JAVA case is
WARN Possible Unhandled Promise Rejection (id: 0):
Error: general.extension.not.initialized

[AEPMobileEdgeIdentity getExperienceCloudId:^(NSString * _Nullable experienceCloudId, NSError * _Nullable error) {
resolve(experienceCloudId);
if (error) {
reject(EXTENSION_NAME, FAILED_TO_CONVERT_EVENT_MESSAGE, nil);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning FAILED_TO_CONVERT_EVENT_MESSAGE, can we read the AEPError message from error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to write it as this way right now
reject(EXTENSION_NAME, nil, error);
Sample output:
WARN Possible Unhandled Promise Rejection (id: 0):
Error: The operation couldn’t be completed. (AEPCore.AEPError error 1.)


If use
reject(EXTENSION_NAME, FAILED_TO_CONVERT_EVENT_MESSAGE, error);

Sample output would be generic
WARN Possible Unhandled Promise Rejection (id: 0):
Error: Failed to get Experience Cloud ID

Let me know what you think

add promise reject with error
Updated for callback error
update to final for handleError parameter
Copy link
Contributor

@emdobrin emdobrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good @cacheung , left a few small comments for typos etc.

#pragma mark - Helper methods

- (void) handleError:(NSError *) error rejecter:(RCTPromiseRejectBlock) reject errorLocation:(NSString *) location {
NSString *errorTimeOut = [NSString stringWithFormat:@"%@ call time out", location];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ... call timed out...


- (void) handleError:(NSError *) error rejecter:(RCTPromiseRejectBlock) reject errorLocation:(NSString *) location {
NSString *errorTimeOut = [NSString stringWithFormat:@"%@ call time out", location];
NSString *errorUnexpected = [NSString stringWithFormat:@"%@ all returned an unexpected error", location];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ... call returned an unexpected error ...

if (error && error.code != AEPErrorNone) {
if (error.code == AEPErrorCallbackTimeout)
reject(EXTENSION_NAME, errorTimeOut, error);
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed if there is an else branch.

}

if (error && error.code != AEPErrorNone) {
if (error.code == AEPErrorCallbackTimeout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to always add accolades for if block, even when having one sentence inside that if.

update with review feedback
@cacheung cacheung merged commit 253b2cb into adobe:edgeIdentity Oct 15, 2021
@cacheung cacheung deleted the promiseCheck branch October 15, 2021 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants