-
Notifications
You must be signed in to change notification settings - Fork 407
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 AbortError if fetch is cancelled in-flight #490
base: master
Are you sure you want to change the base?
Conversation
I'm going to test this out tomorrow in my app since it doesn't seem like there are any automated tests for the Javascript code. |
Maybe we re-throw instead of logging for I am still somewhat confused at how calling a non patched "fetch" works given that the promise would be aborted. |
This is my understanding of the situation, but I am also new to using In my application code, I have something like this: export default class extends Controller {
connect() {
this.controller = new AbortController();
}
show() {
const { signal } = this.controller;
fetch("/some/endpoint", { signal })
.then(r => r.text())
.then(html => {
// do some stuff
console.log(html);
})
.catch(() => {});
}
hide() {
this.controller.abort();
}
} If we But the profiler has patched fetch("/some/endpoint", { signal })
.then(r => r.text())
.then(html => {
// do some stuff
console.log(html);
})
.catch(() => {})
.then(response => {
// do the rack-mini-profiler stuff since the response is finished
}) Since the additional |
Codecov Report
@@ Coverage Diff @@
## master #490 +/- ##
=======================================
Coverage 88.64% 88.64%
=======================================
Files 18 18
Lines 1250 1250
=======================================
Hits 1108 1108
Misses 142 142 Continue to review full report at Codecov.
|
This is where I am getting really confused: From my reading of this code it should be running:
Something about the implementation in mini profiler does not feel right, maybe we should refactor this code a bit so it is clearer, this giant try catch nest is not that easy to understand. |
Ah, I think you are right and maybe this https://github.com/MiniProfiler/rack-mini-profiler/blob/master/lib/html/includes.js#L983-L985 is actually where the edit: I think I am now equally confused! If the request is aborted then it should not even get into the patched |
After more testing, I think we were both wrong. The Promise chain "forks" since RMP returns the original This makes sense because even when I was getting the unhandled exceptions, my app was still working correctly.
So whatever my application code does has no bearing on the exception handling in the profiler (and vice-versa). I think the original solution then would be best: the profiler will need to shallow the AbortError to avoid to extra noise in JS error tracker and confusion when developing. The PR as it currently exists seems good to me and resolves my issue after testing. |
Just lost 3 hours debugging this until I found that the mini-profiler monkey-patches |
We also spent way too much time trying to figure out why this error was appearing in our error tracker. Any chance of getting this merged? |
Resolves #489
Per guidance here: https://developers.google.com/web/updates/2017/09/abortable-fetch#reacting_to_an_aborted_fetch
Users may choose how to handle the rejected promise in their own code, but the profiler will not raise an uncaught exception.