How to handle unsuccessful redirection

How do I handle failed redirections in javascript?

Basically I have like 3 window.open("my.url.here/example/example"). Before doing this, user must login first and then run this html file. (don't mind this login thing in for my question)

However for the logic of the goal, if the first window.open("my.url.here/example/example") isn't right then it will redirect the user into logout which is in my case, what I want to is do is to prevent the redirection for the logout and just proceed to my second window.open("mysecond.url.here/exampl/example").

Blockquote

function func()
        {
      window.open("https://my.url.here/example/example","_self");

      window.open("https://my2nd.url.here/example/xample","_self");

      window.open("https://my3rd.url.here/example/example","_self");


        }