最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

我正在尝试部署云功能,并收到此错误'无法读取未定义状态'

运维笔记admin16浏览0评论

我正在尝试部署云功能,并收到此错误'无法读取未定义状态'

我正在尝试部署云功能,并收到此错误'无法读取未定义状态'

我正在尝试编写将数据从Firestore发送到Google工作表的函数。这是我在index.js中的函数:

const {google} = require('googleapis');
const { promisify } = require('util');
exports.loadInformation = functions.firestore.document('incident-report/{id}').onCreate((err, req, res, next) => {
  console.log('I am triggered')

    google.auth.getClient({
      scopes: [''],
    }).then(auth => {
      const api = google.sheets({ version: 'v4', auth });
      const getSheets = promisify(api.spreadsheets.get.bind(api.spreadsheets));
      return getSheets({ spreadsheetId: '1hCF8jDt6uqYZ7qC93To2n0MbGzDWPIBU72IMp2xqh5Y' });
    })
      // This just prints out all Worksheet names as an example
      .then(({ data: { sheets } }) => {
        res.status(200).send({ sheets });
      })
      .catch(err => {
        res.status(500).send({ err });
      })
});

我收到以下错误。TypeError:无法读取未定义的属性“状态”

我该如何解决?我的功能看起来不错吗。

回答如下:

Firestore onCreate触发器需要一个带有两个参数而不是四个参数的处理程序(函数)。之所以抱怨res未定义,是因为该参数上没有传递任何内容,因为它是仅传递两个(DocumentSnapshot和EventContext)的函数中的第三个参数。给这些文档读GCP Firestore和Firebase Firestore,它应该可以带您进入正确的轨道。另请注意,所有示例均未使用常见的错误优先回调样式,例如(err, ...) => ...

发布评论

评论列表(0)

  1. 暂无评论