levibostian / ExpressjsBlanky

Blank Express.js project to get up and running FAST.
MIT License
7 stars 0 forks source link

Better Sequelize error logging #25

Closed levibostian closed 4 years ago

levibostian commented 4 years ago

At this time, when there is any error at all in the API application, we record the error in Honeybadger. We capture the Error object's message and stacktrace.

But sometimes, there are custom error objects being thrown. A very common scenario would be Sequelize.

In Honeybadger, I have a generic exception that gets thrown: SequelizeUniqueConstraintError. In honeybager, this error stacktrace and message are not helpful at all:

2020-04-29 at 11 52 AM

This is the error message and stacktrace you always get. No matter the endpoint, no matter the unique constraint error. You just get this.

Because this generic error is the 1 exception that is being thrown for all unique constraints that could happen in the app, it's not helpful at all.

Sometimes it's because of a unique constraint I set. Sometimes it's the sequence ID needing reset.

We need to have error handling for Sequelize and other custom errors to better log them.

Here are custom error objects from Sequelize. here is an example dump someone made for reference.

Proposal

For all DB operations that happen, have an error handler. The error handler will catch the error, parse it, and if it finds one of the custom errors from Sequelize, it will cast the error and then log to honeybadger a more detailed error giving the full details of the error.

This will help us to get a much better error logged for an exception because we will get more then just unique exception. Hopefully, we can...

  1. Get the actual error from postgres defining what was unique that failed.
  2. The stacktrace will be more accurate. Right now, we are getting a stacktrace that is just full of sequelize code. It would be great if we can have the stacktrace link to our DB function that we run in our app code so we can find out exactly what query was run in our app code.
levibostian commented 4 years ago

Done.