title: Is wrapping a promise in a try/catch block the proper method?
body: <p>I have a function that calls a promise. On success or failure I would like to return some data beyond what the promise returns.</p>
  
  <p>I thought this might work:</p>
  
  <pre><code>function foo() {
    const extra = 'bar'
    return thepromise().then((res) =&gt; {
      return {
        result: res,
        data: extra
      }
    }, (err) =&gt; {
      // this will not happen if an error is thrown in the called promise
      return {
        result: res,
        data: extra
      }
    })
  }
  
  foo().then((res) =&gt; { }, (err) =&gt; { // error result ends up here })
  </code></pre>
  
  <p>However this does not work. if an error is thrown in the <code>thepromise</code> it will not call the catch block but instead the catch block of <code>foo()</code>.</p>
  
  <p>What is the proper way to handle this? I am successful with a try/catch block but I am not sure this is the best approach:</p>
  
  <pre><code>function foo() {
    const extra = 'bar'
    return new Promise((resolve, reject) =&gt; {
      try {
        return thepromise(p)
      } catch (e) {
        reject(e)
      }
    })
    .then(function(res) {
      return {
        result: res,
        data: extra,
        status: 'success'
      }
    }, function(err) {
      return {
        result: err,
        data: extra
        status: 'error'
      }
    })
  }
  </code></pre>