Include PSQL Error Codes in Execution Errors
Some business logic may revolve around the type of PSQL execution error that gets thrown during a query. Libs like node-postgres return the PSQL error code on the error in a field code on the error itself. To match the functionality of those libraries, would it be possible to include the appropriate error code on execution errors thrown via this library?
That could be possible. Actually, I recently began including error messages matching actual pg errors + some details that pg usually provides.
I could also include the error code with that.
That said, most throw new QueryError statements currently only include an error message, and there are A LOT of them... so it would mean finding the corresponding errors for a lot of different errors... so even if its easy to implement (virtually anyone could do it), that is quite a bit of work, in the end.
I just planned to update the error for unique_violation. Looking at your examples, what is the easiest way to get error, details, hint? or do I have to see what pg returns?
Yes, you must try against an actual postgres database to know what is returned :/