-
Notifications
You must be signed in to change notification settings - Fork 16
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
chore: improve error handing for fetch function #267
Conversation
Signed-off-by: Mirko Mollik <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
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.
LGTM
} | ||
await this.validateIntegrity(response.clone(), url, integrity); | ||
return response.json() as Promise<T>; | ||
} catch (error) { | ||
if (error instanceof DOMException && error.name === 'AbortError') { |
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.
In node.js or react native environments, is this still a DOMException
?
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.
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
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.
@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
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.
@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
Improve the fetch function based on the input from #258 + adding with timeout case and allowing to adjust the timeout value