Fork me on GitHub
#sql
<
2020-11-12
>
afhammad11:11:11

Hi, what's the recommended approach to translating Postgres constraint errors into user friendly error messages? (currently using next.jdbc and Hugsql if that helps)

seancorfield15:11:22

I don't know of any libraries to handle that, so I assume folks use custom try/`catch` logic.

dpsutton15:11:16

at my previous job we had some regexes to pull apart the returned error strings from pg and turn it into a data structure. lots of matching on error types, error string, spec errors, etc

lukasz15:11:52

I have this ugly macro https://gist.github.com/lukaszkorecki/9568a224b9e14d7259bc5032ae30ffa1 - it's not great, but works for the most part

afhammad18:11:59

Yeh i’ve gone with status code and string parsing for now, was hoping it was a solved problem though