title: Angular: HttpClient error with empty 200/201 response (always calls JSON.parse(""))
body: <p>While using Angular <code>HttpClient</code> <code>post</code>, it seems the default is to treat the response as JSON string. This caused error even for 201 response when the response body is empty as empty string <code>""</code> fails <code>JSON.parse()</code>.</p>
  
  <p>The solution is to specify <code>responseType: "text"</code> as additional option, so that empty body is not treated as error.</p>
  
  <p>However, the API endpoint does return error description in JSON <strong>when</strong> the request fails (i.e. empty on success, JSON on error).</p>
  
  <p>How do you construct the <code>HttpClient</code> <code>post</code> so that I can get the error message object back when it fails and success does not count as error?</p>
  
  <p>e.g.:</p>
  
  <pre><code>.subscribe(() =&gt; {
      // do something for success, no return object as the body is empty
    , error =&gt; {
      // do something with the returned error object
      // right now success is still counted as an error due to the issue above
    }
  );
  </code></pre>