【问题标题】:I am getting an error when attempting to use sendgrid to send email尝试使用 sendgrid 发送电子邮件时出现错误
【发布时间】:2019-06-21 16:54:21
【问题描述】:

我收到一个错误,我相信它是从 sendgrid 返回的。但是,我在 Twilio/Sendgrid 故障排除文档中找不到此错误。我看到一些对它的引用表明这是版本不匹配的问题。事情是这样的,我对这个项目知之甚少。开发人员不久前离开了。我一直在努力提供帮助,并且相当成功。然而,这个让我难住了。该错误不涉及任何行号或模块(我可以告诉)

这是来自试图发送此电子邮件的云功能的 Firebase 控制台日志:

{ 
 insertId: "000000-55176214-acd2-453d-8258-048000f1e9e3"   
   labels: {…}   
 logName: "projects/wsos-base/logs/cloudfunctions.googleapis.com%2Fcloud-functions"   
 receiveTimestamp: "2019-06-21T16:40:19.541487656Z"   
   resource: {…}   
 severity: "ERROR"   
 textPayload: "TypeError: Object.values is not a function"   
 timestamp: "2019-06-21T16:40:13.253Z"   
 trace: "projects/wsos-base/traces/bdb710bad4f92297c239de4409de2323"   
}

sendgrid.send 调用之前的控制台日志消息显示在日志中。此调用后没有显示任何日志消息。我已经注释掉了整个调用,并且日志文件中没有显示错误。我几乎 100% 肯定这发生在通话中。但是,从查找 sendgrid 的内容来看,我应该期待至少有一个错误号作为响应。我通过替换字符串错误消息确认“catch”正在工作。我确实在日志中看到了该错误消息。当我将其放回原始捕获时,我收到报告的“TypeError ...Object.values ...”消息。没有错误信息。没有行号。没有模块。

return admin.auth().getUser(user)
                      .then(mentorObj => {
                        var mentorEmail = mentorObj.email;
                        var menteeObj = doc2.data();
                        console.log("Sending to Mentor: ", mentorEmail);
                        const confirmationMentor = {
                              to: mentorEmail,
                              from: *******,
                              template_id: ********,    
                              dynamicTemplateData: {
                                name: mentor.firstName,
                             menteeName: "MenteeNameHere"
                          },
                        };
                        console.log("Sent to Mentor: ", confirmationMentor);

                        return sendgrid.send(confirmationMentor)
                          .then(() => {
                            // console.log('Confirmation successfully sent to ' + mentorEmail);
                            console.log("sending to mentee");
...
})
                         .catch(error => console.error(error.toString()));

只需将上面的“error.toString()”替换为“SomeText”即可将控制台中的 TypeError 消息替换为“SomeText”。此外,“发送给学员”不在控制台日志中。此外,所有源代码中的任何地方都没有引用“.values”。

在控制台日志中,我看到 JSON 正在传递:

{ to: '*****',
  from: '*****',
  template_id: '******',
  dynamicTemplateData: { name: 'Rocky McChocolate', menteeName: 'MenteeNameHere' } }

我把它放在一个在线的 JSON 验证器中,它是无效的。但是,我相信这是因为它在日志中的显示方式,而不是 JSON 的实际外观。因为这是有效的,所以我改变的只是模板 ID。 好吧,我想我已经在上面描述了这一点(可能在错误的地方)。 客户有一个 firebase 应用程序,它会发送电子邮件。他们想要一个不同的电子邮件。因此,我创建了电子邮件(在 Twilio/Sendgrid 中),并更改了 template_id 值并期望发送新电子邮件。相反,我收到此错误消息。我已与客户确认,这些电子邮件是在我处理之前发送的。

【问题讨论】:

    标签: javascript google-cloud-functions sendgrid


    【解决方案1】:

    那个错误,"TypeError: Object.values is not a function" 来自您的代码,而不是来自 SendGrid。在某处,某些东西以无效的方式调用 .values,但它不在您在此处显示的代码中。

    你说得对,那不是有效的 JSON。您是否需要在值上调用 toJSON 或类似名称,才能将其转换为 JSON 字符串?

    【讨论】:

    • 不,这不是来自代码。代码中没有调用“.values”。此错误被捕获如下: .catch(error => console.error(error.toString()));不知道为什么,但我不能添加 cr/lf(按 Enter),或者每次我这样做时都会保存更改。 SendGrid 端点需要 JSON。我相信 JSON 无效的原因是由于 console.log 执行格式以写出 JSON。创建 JSON 的行是有效的
    • 进一步描述这一点。我在“返回 sendgrid.send(confirmationMentor).then(...).catch(error => console.error(error.toString())) 之前和之后添加了 console.log 消息。我只看到发生的日志消息在 sendgrid 调用之前。当我简单地将“error.toString()”替换为“这是捕获错误的位置”时,我得到了 TypeError 的文本 INSTEAD…消息。此外,在 .then() 块中,第一个我要做的是放置一条永远不会出现的 console.log 消息。以防万一 .then 块中的某些东西导致错误。它不是。
    猜你喜欢
    • 1970-01-01
    • 2020-04-17
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    相关资源
    最近更新 更多