Firebase Functions - 为什么在“收到来自函数的响应”后,我仍然收到未经处理的错误消息

Firebase Functions - why do I still receive unhandled error message after 'response received from function'

提问人:Louis Sankey 提问时间:12/16/2022 最后编辑:Marc Anthony BLouis Sankey 更新时间:2/8/2023 访问量:156

问:

我认为一旦从云函数收到响应,就意味着该函数终止了。发送响应后,我如何以及为什么仍会收到“您的函数已终止,因为它引发了未处理的错误”?

调用 Response.send,但该函数在调用后仍会引发错误。这是在模拟器中发生的。

RESPONSE RECEIVED FROM FUNCTION: 200, Got Current Logs
⚠  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
⚠  Your function was killed because it raised an unhandled error.

此外,该错误不需要 60 秒,所以我不知道为什么它会说它在 60 秒后超时。

这是代码。

第一部分只是获取一个 url 数组。 然后,它调用 getLogs 函数。这是我最终提出请求并执行其他一些逻辑的地方,但我现在已经删除了它,只是为了模拟已解决的承诺。

我正在将 bluebird promise 用于 promise.map 语法,这是该 http://bluebirdjs.com/docs/api/promise.map.html 的文档

import * as functions from 'firebase-functions'


export const handler = (database: any, urlDate: any) => {
  const scheduleRef = database.collection('NBASchedule')

  return functions.https.onRequest(async (req, response) => {
    const Promise = require('bluebird')
    const urlList: any = []

   scheduleRef.get().then((snapshot:any) => {

    snapshot.docs.forEach((doc: any) => {
      const scheduleGame = doc.data()
      if (scheduleGame.urlString.split('_')[1] === urlDate) {
        const boxScoreUrl = scheduleGame.boxScoreURL
        urlList.push('https://' + boxScoreUrl + '/')
      }
    })

    getLogs()
   }).catch((err:any) => {
    console.log(err)
   })

    async function getLogs() {

      //Promises returned by the bluebird mapper function are awaited for and the returned promise doesn't fulfill until all mapped promises have fulfilled as well.

      await Promise.map(urlList, (url: any) => {
        return new Promise(
          (resolve: any, reject: any) => {
 
            setTimeout(function () {
              resolve(1 + 1)
            }, 500)
          },
          {
            concurrency: 1,
          }
        ).catch(async (err: any) => {
          console.log(err)
        })
      })
      response.send('Got Current Logs')
    }
  })
}

谁能解释为什么我仍然得到“你的函数被杀死,因为它引发了一个未处理的错误。

谷歌云函数 蓝鸟

评论


答: 暂无答案