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

chore: improve error handing for fetch function #267

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

cre8
Copy link
Contributor

@cre8 cre8 commented Jan 13, 2025

Improve the fetch function based on the input from #258 + adding with timeout case and allowing to adjust the timeout value

Signed-off-by: Mirko Mollik <[email protected]>
Copy link
Member

@lukasjhan lukasjhan left a comment

Choose a reason for hiding this comment

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

LGTM

@lukasjhan lukasjhan merged commit 06e3319 into openwallet-foundation:main Jan 13, 2025
8 checks passed
@cre8 cre8 deleted the fix/fetch-timeou-handling branch January 13, 2025 09:21
}
await this.validateIntegrity(response.clone(), url, integrity);
return response.json() as Promise<T>;
} catch (error) {
if (error instanceof DOMException && error.name === 'AbortError') {
Copy link
Contributor

Choose a reason for hiding this comment

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

In node.js or react native environments, is this still a DOMException?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm.. It could be a problem in other platform. I missed exception handling part.
@cre8 I think we should find other way to handle it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@berendsliedrecht @lukasjhan I think we should write a test and find it out. I added this instance of check, otherwise the linter would fail because of the missing type.

I will open a new PR to add tests and to correct it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@berendsliedrecht I ran the test in node pnpm run test:node and it threw me the DomException. I am not sure how it will work with react native since we have no chance here to test it...

One solution would be to replace fetch via a http library like axios. But this will add another external lib

@cre8 cre8 mentioned this pull request Jan 15, 2025
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