繁体   English   中英

Strapi 电子邮件返回 AssertionError [ERR_ASSERTION]:无法包装非错误对象

[英]Strapi Email Returns AssertionError [ERR_ASSERTION]: Cannot wrap non-Error object

我正在使用 Strapi,但无法在开发中使用电子邮件路由。 当我在邮递员中点击/email路由时,它返回内部服务错误。 在终端中,我收到以下错误AssertionError [ERR_ASSERTION]: Cannot wrap non-Error object

我一直在关注这里的文档https://strapi.io/documentation/3.0.0-beta.x/migration-guide/migration-guide-alpha.26-to-beta.html#migrating-plugins以及参考这里有一篇文章

奇怪的是,当我按照文档在另一个项目中设置内置的 Strapi 电子邮件插件时,一切正常。 在我正在处理的新项目中,我或多或少地从我以前的项目中复制了该代码并将其放入新项目中。 但是在新项目中, /email路由似乎不起作用。

这是我在 extensions/email/controllers/Email.js 中使用的代码

module.exports = {
    send: async (ctx) => {
        // Retrieve provider configuration.

        const config = await strapi
            .store({
                environment: strapi.config.environment,
                type: 'plugin',
                name: 'email'
            })
            .get({ key: 'provider' });

        // Verify if the file email is enable.
        if (config.enabled === false) {
            strapi.log.error('Email is disabled');
            return ctx.badRequest(
                null,
                ctx.request.admin ? [ { messages: [ { id: 'Email.status.disabled' } ] } ] : 'Emailis disabled'
            );
        }

        // Something is wrong
        if (ctx.status === 400) {
            return;
        }
        let options = ctx.request.body;
        await strapi.plugins.email.services.email.send(options, config);

        await strapi.plugins['email'].services.email.send({
            to: ctx.request.body.to,
            subject: 'Test message',
            text: 'Test Text'
        });
    }
};

如果有人需要更多信息,或者需要我澄清一些事情,请告诉我。 谢谢!

在电子邮件发送服务中尝试并捕获,您将能够得到这背后的实际错误,就像在我使用 SendGrid 作为邮件提供程序时一样,我采用了相同的方法并在错误正文中找到了这一点

status:403,
[
  {
    message: 'The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements',
    field: 'from',
    help: null
  }
]

将经过验证的电子邮件放入我从 SendGrid 仪表板面板生成的 default_from 密钥后,此问题得到解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM