Home > Back-end >  How would you manually trigger errors to be logged from node express to sentry?
How would you manually trigger errors to be logged from node express to sentry?

Time:12-11

I am currently using a logger with node express called log4js. Whenever I get an error I log it to a file. Log files are hard to read and understand and the logger is kind of useless since I am not looking at the logged errors.

I just set up sentry.

Is there a way I can manually send errors to sentry kind of how I am doing with my current logger, so I can see the errors easily? I dont want to throw an error every time because then it would shut down the node server and it would have to be restarted. There are many times where I have a try catch, and inside the catch I handle it and log the error to fix in the future. I just want to know those errors were triggered and in an easy to see way.

Any ideas?

CodePudding user response:

try {
  // ...
} catch (e) {
  Sentry.captureException(e);
}

For more about triggering your own errors for sentry check out this link from their node express docs

https://docs.sentry.io/platforms/node/guides/express/usage/

  • Related