<p dir="auto">Post request works but response (on code 200) is not returned.</p>
<p dir="auto">axios<br>
.post(url, JSON.stringify(data))<br>
.then((resp) =&gt; {<br>
console.log("resp: ", resp.data.body);<br>
console.log("result: ", resp.data.result);<br>
alert(<code class="notranslate">Success ${JSON.stringify(resp.data.result)}</code>);<br>
})<br>
.catch((err) =&gt; {<br>
console.error("Problem with Add: ", err);<br>
alert(<code class="notranslate">Problem with Add: ${err}</code>);<br>
});<br>
};<br>
when running the same request in postman i get the response with custom error:</p>
<p dir="auto">{<br>
"statusCode": 200,<br>
"headers": {<br>
"Content-Type": "application/json",<br>
"Access-Control-Allow-Headers": "<em>",<br>
"Access-Control-Allow-Origin": "</em>",<br>
"Access-Control-Allow-Methods": "*",<br>
"Access-Control-Allow-Credentials": true<br>
},<br>
"body": ""Success"",<br>
"result": [<br>
{<br>
"@full_error": "ERROR 1062 (23000): Duplicate entry '501151' for key 'PRIMARY'"<br>
}<br>
]<br>
}<br>
Please advise</p>
<p dir="auto"><strong>Describe the bug</strong><br>
<code class="notranslate">axios.post</code> randomly sends duplicate POST request and ignores the first response.</p>
<p dir="auto">The code is below:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class SomeClass extends React.PureComponent
  isReady = true
  submitCounter = 0
  lastSent = null

  // ...

  submit() {
    this.submitCounter++;

    if (!this.isReady) {
      return;
    }

    this.isReady = false;
    
    this.setState({
      isReady: false
    });

    const formData = new FormData();

    formData.append(&quot;ts&quot;, Date.now());
    formData.append(&quot;um&quot;, Math.random().toString(36).substr(2));
    formData.append(&quot;ctop&quot;, this.submitCounter);
    formData.append(&quot;lastSent&quot;, this.lastSent);

    axios
      .post(`https://someurl.here`, formData)
      .then(({data}) =&gt; {
        this.lastSent = dayjs().format(&quot;YYYY-MM-DD HH:mm:ss&quot;);
        this.isReady = true;
        this.submitCounter = 0
        
        if (data.status === false) {
          return;
        }

        this.setState({
          isReady: true
        });
      })
      .catch(err =&gt; {
        console.log(error);
      });
  }

  // ...
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">SomeClass</span> <span class="pl-k">extends</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-c1">PureComponent</span>
  <span class="pl-s1">isReady</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span>
  <span class="pl-s1">submitCounter</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
  <span class="pl-s1">lastSent</span> <span class="pl-c1">=</span> <span class="pl-c1">null</span>

  <span class="pl-c">// ...</span>

  <span class="pl-en">submit</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-c1">this</span><span class="pl-kos">.</span><span class="pl-c1">submitCounter</span><span class="pl-c1">++</span><span class="pl-kos">;</span>

    <span class="pl-en">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-s1">isReady</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">return</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-c1">this</span><span class="pl-kos">.</span><span class="pl-c1">isReady</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>
    
    <span class="pl-c1">this</span><span class="pl-kos">.</span><span class="pl-c1">setState</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
      <span class="pl-c1">isReady</span>: <span class="pl-s1">false</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c1">const</span> <span class="pl-s1">formData</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">FormData</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c1">formData</span><span class="pl-kos">.</span><span class="pl-s1">append</span><span class="pl-kos">(</span><span class="pl-s">"ts"</span><span class="pl-kos">,</span> <span class="pl-c1">Date</span><span class="pl-kos">.</span><span class="pl-c1">now</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-c1">formData</span><span class="pl-kos">.</span><span class="pl-s1">append</span><span class="pl-kos">(</span><span class="pl-s">"um"</span><span class="pl-kos">,</span> <span class="pl-c1">Math</span><span class="pl-kos">.</span><span class="pl-c1">random</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">toString</span><span class="pl-kos">(</span><span class="pl-c1">36</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">substr</span><span class="pl-kos">(</span><span class="pl-c1">2</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-c1">formData</span><span class="pl-kos">.</span><span class="pl-s1">append</span><span class="pl-kos">(</span><span class="pl-s">"ctop"</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">submitCounter</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-c1">formData</span><span class="pl-kos">.</span><span class="pl-s1">append</span><span class="pl-kos">(</span><span class="pl-s">"lastSent"</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">lastSent</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-en">axios</span>
      <span class="pl-kos">.</span><span class="pl-s1">post</span><span class="pl-kos">(</span>`<span class="pl-s1">https</span>:<span class="pl-c">//someurl.here`, formData)</span>
      <span class="pl-kos">.</span><span class="pl-s1">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">{</span>data<span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">lastSent</span> <span class="pl-c1">=</span> <span class="pl-en">dayjs</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">format</span><span class="pl-kos">(</span><span class="pl-s">"YYYY-MM-DD HH:mm:ss"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">isReady</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">submitCounter</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
        
        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">status</span> <span class="pl-c1">===</span> <span class="pl-c1">false</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-k">return</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>

        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">setState</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
          <span class="pl-c1">isReady</span>: <span class="pl-c1">true</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">.</span><span class="pl-c1">catch</span><span class="pl-kos">(</span><span class="pl-s1">err</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        console<span class="pl-kos">.</span><span class="pl-s1">log</span><span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>

  <span class="pl-c">// ...</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The submit function above is only called once, while the <code class="notranslate">axios.post()</code> is called twice. I know it when I check the <code class="notranslate">ts</code>, <code class="notranslate">um</code>, <code class="notranslate">ctop</code>, and <code class="notranslate">lastSent</code> parameter are same with the previous record. Also, CPanel visitor record show that the request sent twice in short timespan.</p>
<p dir="auto">Is it because the connection issues, or there are some configurations I missed? I already read the documentation, search Google and Stack Overflow, but still no clues about it.</p>
<p dir="auto"><strong>To Reproduce</strong><br>
I don't know how to reproduce it since it's randomly occurred.</p>
<p dir="auto"><strong>Expected behavior</strong><br>
The request is only sent once.</p>
<p dir="auto"><strong>Environment:</strong></p>
<ul dir="auto">
<li>Axios Version: 0.18.0</li>
<li>OS: Windows 7</li>
<li>Browser: Chrome</li>
<li>Browser Version: 75.0.3770.90</li>
<li>Additional Library Versions: React 16.6.3</li>
<li>Server: Laravel 5.7</li>
<li>Database: MySQL 5.7</li>
</ul>