title: Angular2 generates error - Cannot read property '0' of undefined
body: <p>I am following the Tour of Heroes tutorial. Instead of <code>getHero()</code> I have a <code>getCustomer()</code> method. I am getting the following error:</p>
  
  <pre><code>EXCEPTION: Cannot read property '0' of undefined
  </code></pre>
  
  <p>Any ideas why I am getting this error? I think there may be a problem with the <code>handleError()</code> function.</p>
  
  <h2>customer-detail.component.ts</h2>
  
  <pre><code>getCustomer(id: string): void {
      this.customerService.getCustomer(id)
          .subscribe(
              customer =&gt; this.customer = customer,
              error =&gt; this.errorMessage = &lt;any&gt;error
          );
  }
  </code></pre>
  
  <h2>customer.service.ts</h2>
  
  <pre><code>getCustomer(id: string): Observable&lt;Customer&gt; {
      const url = `${this.customerUrl}/${id}`;
      return this.http.get(url)
          .map(this.extractData)
          .catch(this.handleError);
  }
  
  private extractData(res: Response) {
      let body = res.json();
      return body || {};
  }
  
  private handleError(error: Response | any) {
      // In a real world app, you might use a remote logging infrastructure
      let errMsg: string;
  
      if (error instanceof Response) {
          const body = error.json() || '';
          const err = body.error || JSON.stringify(body);
          errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
      } else {
          errMsg = error.message ? error.message : error.toString();
      }
  
      console.error(errMsg);
  
      return Observable.throw(errMsg);
  }
  </code></pre>