title: Async / Await Try Catch Error Handling
body: <p>I'm using the JSONPlaceholder API: <a href="https://jsonplaceholder.typicode.com" rel="nofollow noreferrer">https://jsonplaceholder.typicode.com</a>. I have the following in my <code>service.ts</code>:</p>
  
  <pre><code>public async getPosts(): Promise&lt;Post[]&gt; {
      try {
          const response = await this._http.get&lt;Post[]&gt;(this._baseUrl + "api/JsonPlaceholder/GetPosts");
          return response.toPromise();
      } catch (error) {
          await this.handleError(error);
      }
  }
  </code></pre>
  
  <p>Which I try to use in my <code>component.ts</code>:</p>
  
  <pre><code>public posts: Post[];
  
  public async ngOnInit() {
      const posts = await this._placeholderService.getPosts();
      this.posts = posts;
  }
  </code></pre>
  
  <p>However, the TypeScript compiler throws an error on <code>public async getPosts(): Promise&lt;Post[]&gt;</code> - <code>Function lacks ending return statement and return type does not include 'undefined'.</code></p>
  
  <p>It is expecting a return statement in either the catch block or outside the try-catch. What is best practice for handling errors like this when I want to return a specific type...in my case <code>Post[]</code>. Is there a better way to structure these types of calls?</p>