title: Catch Error response not returning as HttpErrorResponse Object
body: <p>I am trying to catch the exception in the angular service method with the <code>catchError</code>. </p>
  
  <p>Here, in the handleError method, I am trying to cast the error response of <code>HttpErrorResponse</code> but the response is always returning string and in this case it is returning the string <code>Bad Request</code> instead of the <code>HttpErrorResponse</code> object.</p>
  
  <p>The actual error object returning from the node.js service method is of Type <code>Result</code>.</p>
  
  <pre><code>create(data) {
  
      return this.httpClient.post&lt;Result&gt;(this.url, JSON.stringify(data), this.httpOptions)
      .pipe(catchError(e =&gt; this.handleError(e)))
  }
  
  handleError(error: HttpErrorResponse) {
  
    let errorMessage = '';
  
    if (error.error instanceof ErrorEvent) {
        // client-side error
        errorMessage = `Error: ${error.error.message}`;
    } else {
        // server-side error
        //errorMessage = `Error Code: ${error.failMessage}\nMessage: ${error.failMessage}`;
    }
  
    return throwError(error);
  }
  </code></pre>
  
  <p><strong>Result Object</strong></p>
  
  <pre><code>export interface Result
  {
      error: any;
      failMessage: string;
      okMessage: string;
  }
  </code></pre>
  
  <p>And the <strong>node.js</strong> service</p>
  
  <pre><code>function create (req, res, next)
  {
      service.create(req.body)
                  .then(result =&gt; {
                      var statusCode = 200; //default to ok
  
                      if (result)
                      {
                          result.okMessage = "Category Created";
                      }
                      else
                      {
                          statusCode = 400;
  
                          if (result.exception === "duplicate")
                          {
                              result.failMessage = `Category ${req.body.category} is already taken`;
                          }
                      }
  
                      res.status(statusCode).json(result)
                  })
    .catch(err =&gt; next(err))
  }
  </code></pre>