簡體   English   中英

如何捕獲並保存strapi中的所有錯誤?

[英]How to catch and save all errors in strapi?

我正在嘗試將我的strapi 應用程序與哨兵集成,為此我需要編寫一個中間件。 使用以下文檔: 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 以通常的方式打印出錯誤以進行控制台,但錯誤被哨兵應用程序捕獲。

所以,我的問題是:我如何“無縫”捕獲錯誤並將其發送到第三方應用程序,同時不妨礙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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM