title: UnhandledPromiseRejectionWarning: Unhandled promise rejection in _.map in NodeJs
body: <p>I always get the error when I run the code block below -
  UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag <code>--unhandled-rejections=strict</code> (see <a href="https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode" rel="nofollow noreferrer">https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode</a>). (rejection id: 1)</p>
  <pre><code>
  module.exports = (app, spotifyAPI) =&gt; {
  
      app.get('/api/search', requireLogin, async (req, res) =&gt; {
  
          const URI_BASE = keys.ComputerVisionEndpoint + 'vision/v3.0/analyze';
          const imageUrl = &quot;https://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg&quot;; // will be sent as req body
          var results;
  
          // making API call to microsoft cognitive services API 
          try {
              results = await axios({
                  method: 'post',
                  url: URI_BASE,
                  headers: {
                      'Content-Type': 'application/json',
                      'Ocp-Apim-Subscription-Key' : keys.ComputerVision
                  }, 
                  params: {
                      'visualFeatures': 'Tags',
                      'details': '',
                      'language': 'en'
                  },
                  data: {
                  &quot;url&quot;: imageUrl,
                  }
              });
          } catch (err) {
              return res.status(400).send(err);
          }
  
          // remove the common ones - indoor, outdoor, ground, wall, person, woman, man, ceiling, floor
          const to_filter = results['data']['tags'];
          _.remove(to_filter, (item) =&gt; {
              return (item.name === 'indoor' || item.name === 'outdoor' || item.name === 'ground' || item.name === 'wall'
                  || item.name === 'person' || item.name === 'woman' || item.name === 'man' || item.name === 'ceiling'
                  || item.name === 'floor'
              );
          });
  
  
          // searching for relevant songs and adding them to the playlist
          var id;
          try {
              id = await search_and_add(req, res, spotifyAPI, to_filter, playlist_id);
          } catch (err) {
              if (err['statusCode'] === 401) {
                  req.logout();
                  return res.redirect('/');
              }
              else {
                  return res.status(400).send(err);
              }
          }
  
      });
  }
  
  search_and_add = async (req, res, spotifyAPI, to_filter, playlist_id) =&gt; {
      _.map(to_filter, async (tag) =&gt; {
          try {
              const song_details = await spotifyAPI.searchTracks(tag.name, { limit: 1 });
              //const song_uri = song_details['body']['tracks']['items'][0]['id'];
              console.log(song_details);
          } catch (err) {
              throw err;
          }
      });
       return;
      // figure out where to re direct user 
  };
  </code></pre>
  <p>I'm pretty sure it is because of the map statement in the search_and_add function, but I do not know how to get rid of it and provide the same functionality to make the try-catch block work? Could someone help?</p>