plibither8 / refined-hacker-news

✨ Hacker News, but refined — Interface tweaks and features to make the HN experience better
MIT License
808 stars 34 forks source link

fix: Gracefully fail when getUserData fetch returns HTTP 503 #112

Open mlazaric opened 2 years ago

mlazaric commented 2 years ago

I have noticed the same issue described in #102 where the extension is sometimes stuck in the loading wheel phase. After some playing around, it looks like the problem happens when the getUserData fetch returns HTTP response status code 503 which sometimes happens with HackerNews if you refresh quickly or open a lot of links at once. The fetched page looks like this:

image

Because of the 503 page, the resulting topBarElements is empty and actualTopBar is set to undefined which leads to an Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'children') on line 90 of the utils.js file.

Steps to reproduce

  1. Put a breakpoint on line 3080 in file refined-hacker-news.js.
  2. Refresh https://news.ycombinator.com/news a couple of times quickly.
  3. At some point actualTopBar will become undefined.