title: Throw Error with loop of await function
body: <p>I'm struggling with a loop of async await function. I'm creating an API which POST a request to another API. I have to make a loop because users could insert many items at once in the database.</p>
  
  <p>The API that I call rejects Parallel executions so I can't use <code>Promise.all</code> :/</p>
  
  <p>In order to implement that service I made a function to insert one object :</p>
  
  <pre><code>const addValue = async (ID:number, cookie: string) =&gt; {
      try {
          const addValueBody = await addValueQuery(ID:number)
          const header = { 'cookie': cookie, 'content-type': 'application/json' }
          const fetchResult = fetch('http://api-to-call.xyz', { method: `POST`, headers: header, body: addValueBody })
          const response = await fetchResult
          const jsonData = await response.json()
          return jsonData
       } catch (e) {
          throw Error(e.message)
      }
  }
  </code></pre>
  
  <p>And a function which will execute <code>addValue</code> inside a for loop :</p>
  
  <pre><code>const addMulti = async (values: any, cookie: string) =&gt; {
      for (const item of values) {
             await addValue(item.ID, cookie)
      }
  }
  </code></pre>
  
  <p>The problem is that when I call addMulti and  if there is an Error I have a <code>UnhandledPromiseRejectionWarning</code>.</p>
  
  <p>Also I tried to put de <code>for ... in</code> or <code>await addValue</code> inside a <code>try catch</code> but it doesn't catch the Error(s)  </p>
  
  <p>Hence, I have 2 questions :</p>
  
  <p>How can I throw en Error if it occurs during the execution of the loop ?
  Is it possible to break the loop if there is an error ?</p>
  
  <p>Thanks for your help :)</p>