This has happened since a long time ago. We usually don't specify the siteId while loading a page, and in that case we use the current site. However, if the user clicks "logout" or "change site" while a page is being loaded, there is no current site and an error is displayed.
One possible solution is to always pass the siteId, but this means modifying all the pages and some components of the app.
Another solution is to return a certain error in this case, and make the function showErrorModal ignore this error. The calls will still fail, but the user won't see it. There is a problem with this solution: if the user logins in another site while the page is still being loaded, the next WS calls will be done in the new site instead of the old one.