I made a thing that tries to read common Postgres database errors and turn them into error messages that you can expose in a public-facing API, and/or are easier to parse than the native Postgres error equivalents.
Hope you like it! Might be just useful for me, but thought I’d try to share it.
Cool! This is really useful. Bookmarked & I’ll dive into it later & try to give feedback.
What I’ve been doing so far is this recommended method for error catching:
https://github.com/50pop/db-api/blob/master/defs.m4#L12-L23
… which is then used in a PL/pgSQL function like this:
https://github.com/50pop/db-api/blob/master/lat/api.sql#L42-L46
Not so human readable but links to the error code page in the PostgreSQL docs.
One suggestion I have for a release down the road is to work with text bundles of some sort that makes language translations easier. Looks like all the strings, en_US, are hard-coded right now. Had I seen a bundle, I could’ve quickly sent in a pull request for ja_JP.