fix: properly fallback in case of error/rejection of one Toot-ID getting method #72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To implement such a fallback mechanism the extension races two promises against each other here, which have these two methods implemented:
mastodon-simplified-federation/src/background/modules/Detect/Mastodon.js
Line 164 in e340502
Promise.race just has the issue that it also rejects as soon as a promise rejects, i.e. errors.
That's actually not what we want. That works, as long as the success comes before the error, but if the error is instant (which is nearly always the case here because the JSON API is faster than website scraping), then it fails.
We want to ignore errors. I.e. I found something like this SO questions asks for, which points to the modern browser-implemented solution called
Promise.any
.Also needs bumping the Firefox version, but that is not a problem, as that version is really old enough to not be supported anymore. :D
Also implemented a timeout for the API request, so it cannot be stale and hang around forever, which may be bad, too. (At some point we want to show the user an error, after all.)
Fixes #71