简体   繁体   中英

How to catch and save all errors in strapi?

I'm trying to integrate my strapi application with sentry, for which I will need to write a middleware. Use the following documentation: https://strapi.io/documentation/3.0.0-beta.x/advanced/middlewares.html I was able to create a custom middleware with the following:

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

      });
    }
  };
};

However, doing so is preventing strapi to print out the errors to console the usual way but the error is captured by sentry application.

So, my question is : How do I capture the error "seamlessly" and send it to a third party application, at the same time not hinder with the default functioning and error logging of the strapi to console.

Any help would be greatly appreciated!

Thanks:)

EDIT: I figured out that all strapi errors are accessible at the "boom" middleware as pointed out in this file: https://github.com/strapi/strapi/blob/6309af25c921640cb76aeeda463e55db1eb53ef1/packages/strapi/lib/middlewares/boom/index.js#L69

Answer has been given by the authors here: https://github.com/strapi/strapi/issues/4071

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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