如何捕获并保存 strapi 中的所有错误?

How to catch and save all errors in strapi?

我正在尝试将我的 strapi 应用程序与 sentry 集成,为此我需要编写一个中间件。使用以下文档:https://strapi.io/documentation/3.0.0-beta.x/advanced/middlewares.html 我能够使用以下内容创建自定义中间件:

module.exports = strapi => {
  return {
    initialize() {
      strapi.app.use(async (ctx, next) => {
        try {
          await next();
        } catch (error) {
          Sentry.captureException(error)
        }

      });
    }
  };
};

但是,这样做会阻止 strapi 以通常的方式打印出错误以控制台,但错误会被哨兵应用程序捕获。

所以,我的问题是:如何捕获错误"seamlessly"并将其发送给第三方应用程序,同时不妨碍默认将 strapi 的功能和错误记录到控制台。

如有任何帮助,我们将不胜感激!

谢谢:)

编辑: 我发现所有 strapi 错误都可以在 "boom" 中间件中访问,正如该文件中指出的那样:https://github.com/strapi/strapi/blob/6309af25c921640cb76aeeda463e55db1eb53ef1/packages/strapi/lib/middlewares/boom/index.js#L69

作者在这里给出了答案:https://github.com/strapi/strapi/issues/4071