-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to catch and save all errors errors in strapi? #4071
Comments
Hello @saikrishnadeep ! You will have to module.exports = strapi => {
return {
initialize() {
strapi.app.use(async (ctx, next) => {
try {
await next();
} catch (error) {
Sentry.captureException(error);
throw(error);
}
});
}
};
}; |
Hi, what is the sequence of the middlewares? Is this correct (see errorReporting)? {
"timeout": 100,
"load": {
"before": [
"responseTime",
"logger",
"cors",
"responses",
"gzip"
],
"order": [
"Define the middlewares' load order by putting their name in this array is the right order"
],
"after": [
"errorReporting",
"parser",
"router"
]
}
} p.s: Strapi v3.0.0-beta.16.5. Thanks. |
@leonardyhuang You gotta but your error reporting at the ending of everything. Something like this: {
"timeout": 100,
"load": {
"before": [
"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",
"sentry"
]
}
} |
This is now documented at https://strapi.io/documentation/3.0.0-beta.x/guides/error-catching.html#handle-errors Related issue: #2810 |
It would be nice to know how to do this in Strapi V4 |
If you run into issues with the logger not logging something, in the middlewares file move it to the top of the array. I've been meaning to make a PR to do that by default |
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:
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:
strapi/packages/strapi/lib/middlewares/boom/index.js
Line 69 in 6309af2
The text was updated successfully, but these errors were encountered: