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

[达到配额后如何捕获未授权的Sendgrid错误?

运维笔记admin19浏览0评论

[达到配额后如何捕获未授权的Sendgrid错误?

[达到配额后如何捕获未授权的Sendgrid错误?

我可以使用以下简单代码轻松地通过Sendgrid发送电子邮件:

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const sendWelcomeEmail = (email, username, code) => {
    sgMail.send({
        to: email,
        from: '[email protected]',
        subject: 'Welcome!',
        html: '<h3Welcome</h3>'
    });
};

但是,当达到Sendgrid配额(即每天100封免费电子邮件)时,我在服务器上收到此错误:

(node:5060) UnhandledPromiseRejectionWarning: Error: Unauthorized
    at Request._callback (C:\...\node_modules\@sendgrid\client\src\classes\client.js:124:25)

[...]

(node:5060) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


我一直在尝试在不同地方尝试捕获块而没有成功。谢谢。

回答如下:

这是tiguchi评论,我将其发布为可接受的答案:

这是一个NodeJS警告,告诉您向该Promise添加错误处理。只需在发送调用后附加.catch(error => console.error(error))– tiguchi

发布评论

评论列表(0)

  1. 暂无评论