Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: UnhandledPromiseRejection errors #782

Merged
merged 4 commits into from
May 21, 2021
Merged

fix: UnhandledPromiseRejection errors #782

merged 4 commits into from
May 21, 2021

Conversation

fboucquez
Copy link
Contributor

@fboucquez fboucquez commented May 19, 2021

Exception handling simplification in http calls
Defer when loading node info metadata
--unhandled-rejections=strict in tests

Fixes #781

Simplified exception handling.
Defer when loading node info metadata
--unhandled-rejections=strict in tests
Exception handling simplification
const repositoryFactory = new RepositoryFactoryHttp(url);
try {
await repositoryFactory.createNodeRepository().getNodeHealth().toPromise();
expect(true).to.be.false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use chai-as-promised or a similar promise assertion library as a better practice in general for promise assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! chai as promises looks nice. Although the try-catch could be more end-user-style assertion? And I wouldn't add another lib just yet. Let's consider it for the future.

@@ -70,6 +72,17 @@ describe('RepositoryFactory', () => {
expect(repositoryFactory.createFinalizationRepository()).to.be.not.null;
});

it('Raise error without unhandled-rejections', async () => {
const url = 'https://www.google.com';
Copy link
Contributor

Choose a reason for hiding this comment

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

Any other way to achieve this without relying on a remote call? I think we can use sinon to stub the getNodeHealthmethod to throw an 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.

TS SDK uses ts-mockito. I've mocked the low-level generated NodeRoutesApi reflecting how it rejects responses with the current mock lib. The (nodeRepository as any).nodeRoutesApi doesn't look nice, but well.

@rg911 rg911 merged commit 260d978 into dev May 21, 2021
@AnthonyLaw AnthonyLaw deleted the unhandled_exception_fix branch March 6, 2023 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants