【问题标题】:Getting finished with status code: 204 on Firebase Function and nothings happened完成状态码:Firebase Functions 上的 204 并没有发生任何事情
【发布时间】:2021-08-18 14:51:33
【问题描述】:

我正在开发一个向客户发送电子邮件的功能。

exports.sendRestockingNotification = functions.https.onCall((data) => {
  try {
    console.log("Sending confirmation email to the customer...");
    sendEmailRestocking(data.numero, data.nombre, data.emails);
  } catch (error) {
    console.error("Unexpected error: ", error);
  }
});

function sendEmailRestocking (numero, nombre, emails) {
  console.log("Sending Email...");
    return transport.sendMail({
      from: "XXXXX <xxxxxxxxxxxxx@gmail.com>",
      to: emails,
      subject: "El artículo " + nombre + " (" + numero + ") vuelve a estar disponible.",
      html: 
            `
            <div class="container rounded"  style="padding: 10px 30px;">
                <div class="container rounded" style="background-color: #0bbe83;">
                    <h1 style="color: white; padding: 5px;">TejidosPulido</h1>
                </div>
                <div class="row" style="padding: 10px 50px;">
                    <h5 style="color: #0bbe83;">Hola, </h5>
                    <p>
                        El artículo ${nombre} (${numero}) vuelve a estar disponible. ¡Date prisa antes de que se termine!
                    </p>
                </div>
                <br>
                <p style="padding: 10px 30px;"> 
                    Un saludo,
                    <br>
                    Tu equipo TejidosPulido
                </p>
            </div>
          `,
    });
}

但我总是在 Firebase Functions 控制台中得到相同的结果,并且发送了任何邮件,并且调试消息 console.log("Sending a confirmation email to the customer..."); 也没有显示:

sendRestockingNotification ->函数执行开始

sendRestockingNotification -> 函数执行耗时 14 毫秒,完成状态码:204

【问题讨论】:

    标签: node.js firebase google-cloud-functions nodemailer


    【解决方案1】:

    查看Callable Cloud Functions 的文档。您需要返回可以 JSON 编码的数据。

    因此,您需要等待异步sendEmailRestocking() 函数终止,然后再发送响应。例如具有以下改编:

    exports.sendRestockingNotification = functions.https.onCall(async (data) => {  // See async
      try {
        console.log("Sending confirmation email to the customer...");
        await sendEmailRestocking(data.numero, data.nombre, data.emails);
        return {result: "mail send"}; // For example
      } catch (error) {
        // See https://firebase.google.com/docs/functions/callable#handle_errors
        console.error("Unexpected error: ", error);
      }
    });
    

    【讨论】:

    • 我已经尝试了第一个,我也得到了相同的 204 代码
    • 我发现了这个错误。这是客户端的错误,因为在功能完成之前重新加载页面......
    猜你喜欢
    • 2018-09-30
    • 2011-08-12
    • 1970-01-01
    • 2016-08-24
    • 2021-05-13
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多