-
Notifications
You must be signed in to change notification settings - Fork 62
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
Conversation
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 getNodeHealth
method to throw an error.
There was a problem hiding this comment.
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.
Exception handling simplification in http calls
Defer when loading node info metadata
--unhandled-rejections=strict in tests
Fixes #781