如何将所有trapi UI消息错误重定向到控制台?

时间:2020-02-22 15:52:32

标签: strapi

我正在使用 Strapi v3.0.0-beta.18.7

Strapi在UI中引发很多数据库错误,但是从外观上看,内部包含错误的UI块太小,无法读取错误的全文。

如何 将错误消息重定向到文件/控制台到列表中的 有机会阅读所有错误文本?

1 个答案:

答案 0 :(得分:1)

我建议使用自定义中间件来管理您的需求。

以下是创建中间件的文档-https://strapi.io/documentation/3.0.0-beta.x/concepts/middlewares.html

第1步:创建中间件

路径-middlewares/log/index.js

module.exports = strapi => {
  return {
    initialize() {
      strapi.app.use(async (ctx, next) => {
        await next();

        const status = ctx.status;

        if (status < 200 || status >= 300) {
          console.log(ctx.body);
        }
      });
    },
  };
};

第2步:启用中间件

路径-config/environments/development/middleware.json

{
  "log": {
    "enabled": true
  }
}

步骤3:以正确的顺序设置中间件

路径-config/middleware.json

{
  "timeout": 100,
  "load": {
    "before": [
      "log",
      "responseTime",
      "logger",
      "cors",
      "responses",
      "gzip"
    ],
    "order": [
      "Define the middlewares' load order by putting their name in this array is the right order"
    ],
    "after": [
      "parser",
      "router"
    ]
  }
}