title: How to reject promise and handle/catch error in Angular2
body: <p>I'm learning Angular2 and want to do a proper error handling of a method inside a service.</p>
  
  <p>For testing purpose I changed the API, so that I get an invalid result for testing. I want to reject the Promise <code>("Received unexcepted data.")</code> and store the error message inside my angular-component.</p>
  
  <p>My service method:</p>
  
  <pre><code>getBlocks(): Promise&lt;Block[]&gt; {
      return this.http.get(this.serviceUrl)
          .toPromise()
          .then(response =&gt; {
              if (response.json() instanceof Array) {
                  return response.json() as Block[];
              } else {
                  Promise.reject('Received unexpected data.');
              }
          })
          .catch(this.handleError);
  }
  
  private handleError(error: any): Promise&lt;any&gt; {
      console.log('An error occurred in MyService', error);
      return Promise.reject(error.message || error);
  }
  </code></pre>
  
  <p>the component where I call the service:</p>
  
  <pre><code>getBlocks(): void {
      this.myService.getBlocks().then(blocks =&gt; {
          this.blocks = blocks;
      }, error =&gt; {
          console.log('fail callback');
          this.error = error;
      }).catch(e =&gt; {
          console.log('catch');
          this.error = e;
      });
  }
  </code></pre>
  
  <p>I tried to implement the fail-callback of the promise, but my app keeps crashing with</p>
  
  <blockquote>
    <p>ERROR Error: Uncaught (in promise): Received unexpected data.</p>
  </blockquote>
  
  <p>So there is my error message, but it didn't get handled in my component correctly. How can I catch my Promise.reject() from the service correctly, so that I can store the error for example inside <code>this.error</code> variable.</p>
  
  <p>Additional question:
  I have implemented a success and fail callback of the then()-call. Is the catch() after that even necessary? Or should that only be done without a fail-callback? or are those two cases not comparable?</p>