title: jquery post request catching failed request
body: <p>In the front-end JS, I am sending a request to the backend:</p>
  <pre><code>  $.post(&quot;/test&quot;, data, () =&gt; {
      console.log(&quot;received&quot;);
    })
      .done(() =&gt; {
        console.log(&quot;request finished&quot;);
      })
      .fail(function() {
        console.log(&quot;error&quot;);
      })
  </code></pre>
  <p>In the backend, I am purposely causing the request to fail:</p>
  <pre><code>app.post(&quot;/test&quot;, (req, res) =&gt; {
    res.status(400).send(&quot;Error message&quot;);
  })
  </code></pre>
  <p>Apparently, the 400 error was not caught by the <code>.fail</code> block. I later tried using try catch block:</p>
  <pre><code>  try {
      await $.post(&quot;/test&quot;, data, () =&gt; {
        console.log(&quot;received&quot;);
      })
    }
    catch (error) {
      console.log(error);
    }
  </code></pre>
  <p>Still, the error slipped. I ran out of ideas now. How should I catch the error returned by the jquery post request then?</p>