slonik icon indicating copy to clipboard operation
slonik copied to clipboard

`queryExecutionError` interceptor does not intercept assertion errors

Open aravindanve opened this issue 3 years ago • 2 comments

The fact that queryExecutionError interceptor does not catch assertion errors may be intentional, because it is technically not a query execution problem. But, I'm trying to add additional metadata to SlonikErrors so that I can log failed queries and values later in my application. That is just my specific case, but I'm sure being able to intercept all slonik errors would be handy on numerous occasions.

Expected Behavior

Need a way to intercept NotFoundError and DataIntegrityError

Current Behavior

There is only one hook for intercepting errors and it does not intercept assertion errors like NotFoundError and DataIntegrityError

createPool('...', {
  queryExecutionError: (ctx, query, error) => {
    // not called on `NotFoundError` and `DataIntegrityError`
  }
})

Possible Solution

Either

createPool('...', {
  queryExecutionError: (ctx, query, error) => {
    // must be called on `NotFoundError` and `DataIntegrityError`
  }
})

Or

createPool('...', {
  queryExecutionError: (ctx, query, error) => { ... },
  queryAssertionError: (ctx, query, error) => {
    // must be called on `NotFoundError` and `DataIntegrityError`
  }
})

Any thoughts?

aravindanve avatar Oct 06 '20 04:10 aravindanve

Would also be interested in this!

jareware avatar Aug 10 '21 14:08 jareware

This would be really helpful for us as well, some way to be able to log / catch any query error and log the sql query that was used when the error occurred.

vrecan avatar Feb 02 '22 23:02 vrecan

I am closing this due to inactivity, but if you have examples of how'd use this then please share in this thread and I will do my best to accommodate it. In particular, I would like to see what kind of information you'd try to attach to the error/logs to enhance debugging. If something is missing from the default implementation, I'd rather implement this into the core.

gajus avatar Sep 29 '23 16:09 gajus