-
Notifications
You must be signed in to change notification settings - Fork 142
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
🐛 Handle non-object response and error #2860
Conversation
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
…observable-response
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2860 +/- ##
==========================================
- Coverage 93.67% 93.65% -0.02%
==========================================
Files 266 266
Lines 7586 7585 -1
Branches 1688 1688
==========================================
- Hits 7106 7104 -2
- Misses 480 481 +1 ☔ View full report in Codecov by Sentry. |
…observable-response
…observable-response
responsePromise.then( | ||
monitor((response) => reportFetch(response)), | ||
monitor((error) => reportFetch(error, true)) | ||
) |
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.
💭 thought: Thank you for doing this! I don't think there is a good reason to have all those checks. I think we could remove them, this would allow a simpler approach:
responsePromise.then( | |
monitor((response) => reportFetch(response)), | |
monitor((error) => reportFetch(error, true)) | |
) | |
function reportFetch(partialContext: Partial<FetchResolveContext>) { | |
const context = startContext as unknown as FetchResolveContext | |
context.state = 'resolve' | |
assign(context, partial) | |
observable.notify(context) | |
} | |
responsePromise.then( | |
monitor((response) => { | |
reportFetch({ | |
response, | |
responsType: response.type, | |
status: response.status, | |
isAborted: false | |
}) | |
}), | |
monitor((error: unknown) => { | |
reportFetch({ | |
status: 0, | |
isAborted: response instanceof DOMException && response.code === DOMException.ABORT_ERR, | |
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.
Done, and added support for AbortController.
}) | ||
}), | ||
monitor((error: Error) => { | ||
const isAborted = |
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.
🥜 nitpick: You could inline it
reportFetch({
status: 0,
isAborted:
context.init?.signal?.aborted || (error instanceof DOMException && error.code === DOMException.ABORT_ERR),
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.
Done
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.
It could be nice to have a test with AbortSignal :)
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.
Done
👏 praise: Very nice simplification!! |
@@ -14,7 +14,7 @@ export function mockFetch() { | |||
} | |||
} | |||
|
|||
window.fetch = (() => { | |||
window.fetch = ((...[, init]) => { |
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.
❓ question: Just out of curiosity, do you know how this is transpiled in ES5? :)
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.
Though, this syntax is a bit surprising :D
Suggestion:
window.fetch = (_input, init) => {
..
}
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.
It makes sense when you think about it, but I prefer benoit's suggestion (so I don't have to think about it 😄)
Or event (input, init) => {
with args-after-used
@@ -14,7 +14,7 @@ export function mockFetch() { | |||
} | |||
} | |||
|
|||
window.fetch = (() => { | |||
window.fetch = ((...[, init]) => { |
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.
Though, this syntax is a bit surprising :D
Suggestion:
window.fetch = (_input, init) => {
..
}
Motivation
We have a lot of telemetry errors concerning Fetch error that are not an Error object but a string or undefined.
Changes
Testing