【问题标题】:Strapi Email Returns AssertionError [ERR_ASSERTION]: Cannot wrap non-Error objectStrapi 电子邮件返回 AssertionError [ERR_ASSERTION]:无法包装非错误对象
【发布时间】:2020-06-05 04:52:48
【问题描述】:

我正在使用 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 此处的文档以及参考文章here

奇怪的是,当我按照文档在另一个项目中设置内置的 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'
        });
    }
};

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

【问题讨论】:

  • 几周前遇到了同样的问题。你有解决办法吗?
  • 还是没有解决办法。考虑到我在另一个项目中有完全相同的代码并且电子邮件在那里工作,但不是在这里,这真的很奇怪。如果我无法弄清楚这一点,我正在考虑回滚我的肩带版本。你找到解决办法了吗?
  • 没有。我也没有解决办法……

标签: javascript node.js strapi


【解决方案1】:

在电子邮件发送服务中尝试并捕获,您将能够得到这背后的实际错误,就像我使用 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 键中放入经过验证的电子邮件后,此问题得到了修复。

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 2021-02-21
    • 2021-12-23
    • 2016-05-27
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 2021-09-30
    • 2020-04-16
    相关资源
    最近更新 更多