slonik
slonik copied to clipboard
`queryExecutionError` interceptor does not intercept assertion errors
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?
Would also be interested in this!
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.
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.