Retry XMLHttpRequest Carefully
11–20 of 23 posts
Re: Retry XMLHttpRequest Carefully
#12This post reminded of a /fun/ bug I ran into at my last job. The root of the issue was our server was returning a 408 timeout error when something timed out on the backend. Astute readers might immediately notice an issue with that code, mainly that it's for a /client/ timeout not 504 (server timeout). Since we controlled the client and server you might think it doesn't matter much, as long as the client knows how to…
Sure, don't display it in the UI, but if the browser is retrying something I sure want to know about it when debugging!
Odd.
Re: Retry XMLHttpRequest Carefully
#13This post reminded of a /fun/ bug I ran into at my last job. The root of the issue was our server was returning a 408 timeout error when something timed out on the backend. Astute readers might immediately notice an issue with that code, mainly that it's for a /client/ timeout not 504 (server timeout). Since we controlled the client and server you might think it doesn't matter much, as long as the client knows how to…
Really curious what the use case is for dev tools hiding a network request from you? Sure, don't display it in the UI, but if the browser is retrying something I sure want to know about it when debugging! Odd.
Re: Retry XMLHttpRequest Carefully
#14Just use axios and https://www.npmjs.com/package/retry-axios
Re: Retry XMLHttpRequest Carefully
#15Very nice write-up. I'd be curious to see it using fetch rather than the older xhr Api - that would make more sense as a library today I think? Or are there compelling reasons to stick with xhr in a post-ie world?
https://pouchdb.com/2015/05/18/we-have-a-problem-with-promis...
Re: Retry XMLHttpRequest Carefully
#16Very nice write-up. I'd be curious to see it using fetch rather than the older xhr Api - that would make more sense as a library today I think? Or are there compelling reasons to stick with xhr in a post-ie world?
I still use xhr because of familiarity. Using a javascript closure as a callback in xhr works quite well and seems much easier to me than dealing with the promises that are required for fetch. (I understand what promises are; I just think the ones in javascript are poorly-defined.) https://pouchdb.com/2015/05/18/we-have-a-problem-with-promis...
> Awaiting async/await
> That's the point I made in "Taming the asynchronous beast with ES7", where I explored the ES7 async/await keywords, and how they integrate promises more deeply into the language. Instead of having to write pseudo-synchronous code (with a fake catch() method that's kinda like catch, but not really), ES7 will allow us to use the real try/catch/return keywords, just like we learned in CS 101.
> This is a huge boon to JavaScript as a language. Because in the end, these promise anti-patterns will still keep cropping up, as long as our tools don't tell us when we're making a mistake.
Async/await is extremely well-supported and reliable in the ecosystem now, and allows you to express Promise-based asynchronous flows with a much more natural syntax. I highly recommend that you take a look, as it pretty much obviates all the pain points mentioned in the linked article.
Re: Retry XMLHttpRequest Carefully
#17This is a good introduction to the subject. At the end you might want to mention rate limiting, truncation (giving up after a specified number of retries) and, for the most sophistication, circuit breakers.
Thank you for your suggestions! I'll see if I can write a few intelligent sentences on these (somewhat more advanced) subjects.
Re: Retry XMLHttpRequest Carefully
#18Earlier quoted context omitted.
I still use xhr because of familiarity. Using a javascript closure as a callback in xhr works quite well and seems much easier to me than dealing with the promises that are required for fetch. (I understand what promises are; I just think the ones in javascript are poorly-defined.) https://pouchdb.com/2015/05/18/we-have-a-problem-with-promis...
From the end of the article you linked: > Awaiting async/await > That's the point I made in "Taming the asynchronous beast with ES7", where I explored the ES7 async/await keywords, and how they integrate promises more deeply into the language. Instead of having to write pseudo-synchronous code (with a fake catch() method that's kinda like catch, but not really), ES7 will allow us to use the real try/catch/return keyw…
Re: Retry XMLHttpRequest Carefully
#19This post reminded of a /fun/ bug I ran into at my last job. The root of the issue was our server was returning a 408 timeout error when something timed out on the backend. Astute readers might immediately notice an issue with that code, mainly that it's for a /client/ timeout not 504 (server timeout). Since we controlled the client and server you might think it doesn't matter much, as long as the client knows how to…
Really curious what the use case is for dev tools hiding a network request from you? Sure, don't display it in the UI, but if the browser is retrying something I sure want to know about it when debugging! Odd.
Re: Retry XMLHttpRequest Carefully
#20Very nice write-up. I'd be curious to see it using fetch rather than the older xhr Api - that would make more sense as a library today I think? Or are there compelling reasons to stick with xhr in a post-ie world?
Use case: I was fetching a large image from a server to render into a canvas and I wanted to show a progress bar for the download. AFAIK there is no way to do this with fetch