title: How to prevent axios.interceptors.response.use to crash the error handling?
body: <p>I have several forms &quot;Login, Registration, Create a product...&quot; For these forms, I was handling errors with useState for the front end and for the back end with express-validator.</p>
  <p>Everything worked perfectly, I received error messages as expected.</p>
  <p>But now, I realize that none of these forms manage errors anymore. Since I set up my <code>axios.interceptors.response.use</code> to send the user back to the login page if he has a 403 status (This is my way of handling a token that expires).</p>
  <p>Here is my code that NORMALLY shows me the errors :
  (For example, this is my login page where I only get one error message)</p>
  <pre class="lang-js prettyprint-override"><code>axios.interceptors.request.use(
    (config) =&gt; {
      config.headers.authorization = `Bearer ${localStorage.getItem('UserToken')}`;
      return config;
    },
    (error) =&gt; {
      return Promise.reject(error);
    },
  );
  
  axios.interceptors.response.use(
    (response) =&gt; response,
    (error) =&gt; {
      if (error.response.status === 403) {
        localStorage.clear();
        window.location.href = '/connexion';
      }
    },
  );
  
  export default function ConnexionPage() {
    // Redirection Connexion réussite vers Accueil
    const history = useHistory();
  
    const [errorForm, setErrorForm] = useState();
  
    // Connexion
    const handleSubmit = (event) =&gt; {
      event.preventDefault();
      login(event.target.email.value, event.target.password.value)
        .then((response) =&gt; {
          const Token = response.data.accessToken;
          localStorage.setItem('UserToken', Token);
          User = jwt_decode(Token);
          localStorage.setItem('User', JSON.stringify(User));
          history.push({
            pathname: '/',
          });
          window.location.reload(false);
        })
        .catch((err) =&gt; {
          setErrorForm(err.response.data);
        });
    };
  
    // Classe de style
    const classeConnexion = ConnexionStyle();
  
    return (
      &lt;Grid&gt;
        &lt;Card style={{ height: 500, marginTop: '5%', marginRight: '10%', marginLeft: '10%' }} variant=&quot;outlined&quot;&gt;
          &lt;Grid align=&quot;center&quot;&gt;
            &lt;Avatar className={classeConnexion.avatar}&gt;
              &lt;LockOutlinedIcon&gt;&lt;/LockOutlinedIcon&gt;
            &lt;/Avatar&gt;
            &lt;h2&gt;Connexion :&lt;/h2&gt;
            {errorForm &amp;&amp; &lt;p style={{ color: 'red' }}&gt;{errorForm}&lt;/p&gt;}
          &lt;/Grid&gt;
  
          &lt;form onSubmit={handleSubmit}&gt;
            &lt;TextField
              id=&quot;email&quot;
              name=&quot;email&quot;
              label=&quot;Email :&quot;
              placeholder=&quot;Entrez votre mail.&quot;
              fullWidth
              variant=&quot;outlined&quot;
              style={TextFieldStyle}
              required
            /&gt;
  
            &lt;TextField
              style={TextFieldStyle}
              id=&quot;password&quot;
              name=&quot;password&quot;
              label=&quot;Mot de passe :&quot;
              placeholder=&quot;Entrez votre mot de passe.&quot;
              type=&quot;password&quot;
              fullWidth
              variant=&quot;outlined&quot;
              required
              autoComplete=&quot;on&quot;
            /&gt;
  
            &lt;Button endIcon={&lt;CheckIcon /&gt;} className={classeConnexion.root} type=&quot;submit&quot; variant=&quot;contained&quot; fullWidth&gt;
              Connexion
            &lt;/Button&gt;
          &lt;/form&gt;
  
          &lt;Typography&gt;
            &lt;Link href=&quot;/inscription&quot;&gt;Pas de compte ? Créez-en un.&lt;/Link&gt;
          &lt;/Typography&gt;
        &lt;/Card&gt;
      &lt;/Grid&gt;
    );
  }
  </code></pre>
  <p>PS: I'm still a simple student, having to make an e-commerce site as an exercise.</p>
  <p>EDIT :
  Yes, it's my <code>axios.interceptors.response.use</code> that make my error handling getting ignored or make the application crash</p>