module.exports = strapi => { return { initialize() { strapi.app.use(async (ctx, next) => { try { await next(); } catch (error) { if (typeof error === 'string' || error instanceof String) { strapi.services["system-log"].create({ type: "global", message: error }); } else { strapi.services["system-log"].create({ type: "global", stack: error.stack, message: error.message }); } throw error; } }); }, }; };