title: Error: Function returned undefined, expected Promise or value
body: <p>I setup a pubsub function with firebase functions to do some operations every so often in the Firestore. In order to do this I need to make a request to a third party API to get the updated data and then I want to insert that data into the correct collection and document in the Firestore.</p>
  
  <pre class="lang-js prettyprint-override"><code>const request_promise = require('request-promise')
  
  exports.scheduledFunction = functions.pubsub.schedule('every 2 minutes').onRun((context) =&gt; {
      console.log('This will be called every 2 minutes')
      var username = ''
      var password = ''
      var options = {
          url: 'path.to.api.com',
          auth: {
              user: username,
              password: password
          },
          json: true
      }
  
      request_promise(options)
          .then(function (product) {
              console.log(product.product_id)
              db.collection('products').doc(product.product_id).set(product)
                  .then(() =&gt; {
                      console.log('Document successfully written')
                  })
                  .catch(error =&gt; {
                      console.log('Error writing product to firestore', error)
                  })
          })
          .catch(function (err) {
              console.log('Failed to get product', error)
          })
    });
  </code></pre>
  
  <p>In the code above if I comment out the call to add the data to the Firestore I the correct product_id prints to the console, so I know the request is working but with it left in I get 'Function returned undefined, expected Promise or value'.</p>