title: Angular 2 how to read Custom error message from backend
body: <p>My problem with Angular 2 that was not exist in AngularJS, that I was sending the error message as a string with backend API call in case I have error, with  error status 401 as example, the problem now that I can't read this message from Angular2 http response message, while I can do that from AngularJS:</p>
  
  <p>I tried the following codes and nothing was helpful: </p>
  
  <p><strong>Promise:</strong></p>
  
  <pre><code>this._http.post('/login',{email: 'email@example.com', password: '123'})
              .toPromise()
              .then((resp) =&gt; console.log(resp), (error) =&gt; console.log(error));
  </code></pre>
  
  <p><strong>Observable:</strong> </p>
  
  <pre><code>this._http.post('/login',{email: 'email@example.com', password: '123'})
      .subscribe(response =&gt;console.log(response), (error) =&gt; console.log(error));
  </code></pre>
  
  <p>And from back-end I send response as a text, for OK or Unauthorized, for OK i send back <code>String token == UUID.randomUUID().toString();</code>, for error I send back message like <code>String error = " Invalid credentials ";</code>, the problem is that the <code>console.log</code> works and print the text for success (token in this case), but in case error, its just prints: <code>Response with status: 200  for URL: null</code>. </p>
  
  <p>If I change code to <code>JSON.stringify(error)</code> I get something like this: </p>
  
  <pre><code>{"_body":{},"status":401,"ok":false,"statusText":"Unauthorized","headers":{"null":["HTTP/1.1 401 Unauthorized"],"Access-Control-Allow-Headers":["Origin"," X-Requested-With"," Content-Type"," Accept"," Referer"," User-Agent"],"Access-Control-Allow-Met
  hods":["POST"," GET"," PUT"," DELETE"," OPTIONS"],"Access-Control-Allow-Origin":["*"],"Allow":["*"],"Content-Length":["36"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Tue"," 23 Aug 2016 14:53:25 GMT"]},"type":2,"url":null}
  </code></pre>
  
  <p>As you can see the error test not even mentioned inside the Object !!</p>
  
  <p>I tried to change the response for error from backend to return json like this:</p>
  
  <pre><code>{
     "message": "invalid email or password"
  }
  </code></pre>
  
  <p>I can get the result inside <code>_body</code>, and I can only read it like this: <code>console.log(error._body.message)</code> ! but i feel its something wrong this way, and I don't want to response as a json in this case.</p>
  
  <p>For angularjs (angular 1), its so simple just to print the response and everything is cool, while in angular 2 its a really problem.</p>
  
  <p>What the problem, and how I can solve this issue without any refactor to backend?</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I'm using Angular 2.0.0-rc.4 and same for http : `"@angular/http": "2.0.0-rc.4"</p>