title: Promise then and catch clauses not working
body: <h1>Background</h1>
  
  <p>I have a multitude of functions that may or may not return a Promise and that may or may not fail, like in the examples below:</p>
  
  <pre><code>let goodFun = (fruit) =&gt; `I like ${fruit}`;
  
  let badFun = (fruit) =&gt; {
      throw `${fruit} is spoiled!`;
  };
  
  let badPromise = (fruit) =&gt; new Promise( (fulfil, reject) =&gt; {
      reject(`Promise failed with ${fruit}`);
  });
  
  let goodPromise = (fruit) =&gt; new Promise((fulfil, reject) =&gt; {
      fulfil(`Promise succeeded with ${fruit}`);
  });
  </code></pre>
  
  <p>Because each function may or may not return a promise, which may or may not fail, I modified <code>executeSafe</code> from <a href="https://stackoverflow.com/questions/42808381/how-can-i-use-promises-to-catch-errors-when-they-might-not-be-wrapped-in-a-promi">another StackOverflow post</a>, that takes a function and its arguments as parameters, and then <em>Promisifies</em> the function and its result:</p>
  
  <pre><code>let executeSafe =
      (fun, ...args) =&gt; Promise.resolve().then(() =&gt; {
          return fun(...args);
      });
  </code></pre>
  
  <p>My objective with all of this, is to have an <code>asyncFun</code> function that waits for the execution of a batch of functions that were Promisified and then returns whatever came from executing them:</p>
  
  <pre><code>let asyncFun = 
  (fruit) =&gt; 
      Promise.all([badFun, goodFun, badPromise, goodPromise].map(
          fun =&gt; executeSafe(fun, fruit)
      )
  );
  </code></pre>
  
  <h1>Problem</h1>
  
  <p><code>asyncFun</code> is designed to run the multitude of functions previously described and some of them I actually expect to see fail. To accommodate for this my <code>asyncFun</code> function has a <code>catch</code> clause. This clause only works with <code>badFun</code> and doesn't work with <code>badPromise</code>. The <code>then</code> clause never works. </p>
  
  <pre><code>let executor = () =&gt; {
      let fruitsArr = ["banana", "orange", "apple"];
      let results = [];
  
      for (let fruit of fruitsArr)
          results.push(
              asyncFun(fruit)
              .then(res =&gt; {
                  console.log(res);
              })
              .catch(error =&gt; {
                  console.log(`Error: ${error}`);
              })
          );
  
      return Promise.all(results);
  };
  </code></pre>
  
  <p>Not even placing the <code>catch</code> clause in the executor's call catches anything else other than the <code>badFun</code> errors.</p>
  
  <pre><code>executor()
      .catch(error =&gt; console.log("Failed miserably to catch error!"));
  </code></pre>
  
  <h1>Code</h1>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let goodFun = (fruit) =&gt; {
    return `I like ${fruit}`;
  };
  
  let badFun = (fruit) =&gt; {
    throw `${fruit} is spoiled!`;
  };
  
  let badPromise = (fruit) =&gt; Promise.resolve().then(() =&gt; {
    throw `Promise failed with ${fruit}`;
  });
  
  let goodPromise = (fruit) =&gt; Promise.resolve().then(() =&gt; {
    return `Promise succeded with ${fruit}`;
  });
  
  let executeSafe =
    (fun, ...args) =&gt; Promise.resolve().then(() =&gt; {
      return fun(...args);
    });
  
  let asyncFun = (fruit) =&gt; Promise.all([badFun, goodFun, badPromise, goodPromise].map(fun =&gt; executeSafe(fun, fruit)));
  
  let executor = () =&gt; {
    let fruitsArr = ["banana", "orange", "apple"];
    let results = [];
  
    for (let fruit of fruitsArr)
      results.push(
        asyncFun(fruit)
        .then(res =&gt; {
          console.log(res);
        })
        .catch(error =&gt; {
          console.log(`Error: ${error}`);
        })
      );
  
    return Promise.all(results);
  };
  
  executor()
    .catch(error =&gt; console.log("Failed miserably to catch error!"));</code></pre>
  </div>
  </div>
  </p>
  
  <p>Question:</p>
  
  <ul>
  <li>How to fix my code so that its <code>then</code> and <code>catch</code> clauses in <code>asyncFun</code> work as intended?</li>
  </ul>