title: Getting CORS error rather than expected 429 response when rate limit is reached
body: <p>In my backend I implemented an IpRateLimit middleware with the AspNetCoreRateLimit package in my .net core entity framework backend. When an IP Address x makes y calls in a specific time, it gets blocked for a certain time and the backend should return an 429 error and this works fine when testing with postman. But when the I make an request with axios, that is supposed to get blocked because of the ip rate limiter, I receive an axios error:</p>
  <pre><code>&quot;Access to XMLHttpRequest at 'https://localhost:44372/api/Users/Login/' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.&quot;
  &quot;POST https://localhost:44372/api/Users/Login/ net::ERR_FAILED&quot;
  </code></pre>
  <p>After receiving this error, I have added the needed header, but it hasn't changed the result. Other axios requests to my backend (also post, put and delete) work fine, but when the ip rate limiter hits, I just get the cors error.</p>
  <p>I implemented the limiter in my application as in the following tutorial:
  <a href="https://edi.wang/post/2019/6/16/ip-rate-limit-for-aspnet-core" rel="nofollow noreferrer">https://edi.wang/post/2019/6/16/ip-rate-limit-for-aspnet-core</a></p>
  <p>React axios request:</p>
  <pre><code> async function buildPostAndFetch(url, param, header) {
              const finalurl = `${BASE_URL}${url}`;
              return axios.post(finalurl, param, {headers:{&quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;}})
              .then(res =&gt; {
                  response(res);
                  return res.data ? res.data : true;
              })
              .catch(err =&gt; {              
                  handleError(err);
                  return false;
              })        
      }
  
  handleError() {
   const handleError = err =&gt; {
          setError(true);
     
          if(err.request?.status === 0) {
              console.log(&quot;*********************************************&quot;)
              console.log(err.request);
              console.log(&quot;*********************************************&quot;)
              // throw new Error(&quot;API is currently offline or you are not connected to the internet:(&quot;);
          } else if(err.response.status === 429) {
              console.log(&quot;*********************************************&quot;)
              console.log(err.response);
              console.log(&quot;*********************************************&quot;)
          }
      }
  }
  </code></pre>
  <p>When requestion and limiter hits I always get in the err.request.status === 0 path.</p>