title: Angular 4 Restful Post response with "SyntaxError: Unexpected end of JSON input at JSON.parse"
body: <p>Below I have the following Angular segment which appears to attempting to handle the response as JSON even though 'httpOptionsText' is a constant defined as:</p>
  
  <pre><code>const httpOptionsText = {
      headers: new HttpHeaders({
      'Content-Type': 'text/plain'
      })
  }; 
  
  addOrders(order, rootUri): Promise&lt;DetailOrderbean[]&gt; {
  let body = JSON.stringify(order);
  const url = rootUri + 'api/data/addDetailOrder?order=' + body;
  
  return this.http.post&lt;DetailOrderbean&gt;(url, body, httpOptionsText)
      .toPromise()
      .then(res =&gt; {
             console.log(res);
      })
      .catch(this.handleError);
  }
  </code></pre>
  
  <p>Additionally, the java is specifying </p>
  
  <pre><code>        response.setContentType( "text/plain");
          response.setHeader("Access-Control-Allow-Origin", 
          "http://localhost:4200");
          response.setHeader("Access-Control-Allow-Credentials","true");
  </code></pre>
  
  <p>The status is 200, so I just want to consume the error.  However, in the event of an actual error I need the handleError as it exits:</p>
  
  <pre><code>private handleError(error: any): Promise&lt;any&gt; {
      console.error('An error occurred', error);
      return Promise.reject(error.message || error);
  }
  </code></pre>