Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

feat: add get user subscription api call#411

Merged
antsgar merged 19 commits intomasterfrom
feature/add-get-user-subscription-api-call
Sep 9, 2021
Merged

feat: add get user subscription api call#411
antsgar merged 19 commits intomasterfrom
feature/add-get-user-subscription-api-call

Conversation

@antsgar
Copy link
Copy Markdown
Contributor

@antsgar antsgar commented Sep 6, 2021

@antsgar antsgar requested review from atmoio and karolsojko September 6, 2021 05:57
@vardan-arm
Copy link
Copy Markdown
Contributor

vardan-arm commented Sep 8, 2021

@antsgar as an info @standardnotes/snjs with version 2.12.2 is already merged by this PR, so I think it makes sense to bump it to 2.12.3 here.

Comment on lines +566 to +571
if (!response.error && response.data) {
return (response as GetSubscriptionResponse).data!.subscription
}
} catch (e) {
return undefined;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We want the errors to propagate:

if(response.error != null) throw new Error(error.message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And no need to wrap in try/catch. The error that happens in await will automatically be embedded in the error response part of the Promise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines +575 to +583
try {
const response = await this.apiService.getAvailableSubscriptions();
if (!response.error && response.data) {
return (response as GetAvailableSubscriptionsResponse).data!
}
} catch (e) {
return undefined;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here as above.

authentication: this.session?.authorizationValue,
fallbackErrorMessage: messages.API_MESSAGE_FAILED_SUBSCRIPTION_INFO,
});
this.processResponse(response);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think processResponse already happens in this.request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch, thanks! 🙂

Copy link
Copy Markdown
Contributor

@gorjan5sk gorjan5sk left a comment

Choose a reason for hiding this comment

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

Approved! :) One small comment regarding processResponse.

public async getUserSubscription(): Promise<Subscription | undefined> {
const response = await this.sessionManager.getSubscription();
if (response.error) {
throw new Error(response.error.message)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm why are we throwing? We should propagate this to the client so the user can take action. Otherwise this might block execution of other essential tasks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When throwing an error in an async function it triggers the catch/error of the Promise. That's how it's propagated towards the client.

@antsgar
Copy link
Copy Markdown
Contributor Author

antsgar commented Sep 9, 2021

@mobitar the failing e2e test here also failed in your latest commit in the master branch. Safe to ignore?

@atmoio
Copy link
Copy Markdown
Member

atmoio commented Sep 9, 2021

Yep need to look into it. Is a test/deinit issue rather than core issue.

@antsgar antsgar merged commit 83a8518 into master Sep 9, 2021
@antsgar antsgar deleted the feature/add-get-user-subscription-api-call branch September 9, 2021 14:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants