title: How to deal with http status codes other than 200 in Angular 2
body: <p>Right now the way I do http requests (borrowed from <a href="https://stackoverflow.com/a/34758630/4937981">this answer</a>) is this:</p>
  
  <pre><code>POST(url, data) {
          var headers = new Headers(), authtoken = localStorage.getItem('authtoken');
          headers.append("Content-Type", 'application/json');
  
          if (authtoken) {
          headers.append("Authorization", 'Token ' + authtoken)
          }
          headers.append("Accept", 'application/json');
  
          var requestoptions = new RequestOptions({
              method: RequestMethod.Post,
              url: this.apiURL + url,
              headers: headers,
              body: JSON.stringify(data)
          })
  
          return this.http.request(new Request(requestoptions))
          .map((res: Response) =&gt; {
              if (res) {
                  return { status: res.status, json: res.json() }
              }
          });
      }
  </code></pre>
  
  <p>This works fine, except for the fact that angular2 will fail if the status code returned is anything else than 200. For example, if a user wants to post something and the server returns 400, angular 2 will throw the exception:</p>
  
  <blockquote>
    <p>uncaught exception: [object Object]</p>
  </blockquote>
  
  <p>How can I avoid this? I'd like to handle these status codes in my app in order  to enhance user experience (show errors, etc)</p>