Replies: 2 comments
-
See https://github.com/jackc/pgx/wiki/Error-Handling and https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgconn#PgError for how to get the actual error fields. Then https://github.com/jackc/pgerrcode may be of use for named errors that map to SQLSTATE error codes (e.g. 23503 - foreign key violation). |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you. The links are very helpful indeed. The code I was looking for was 23505. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have a unique constraint on an email column. When a user is created with already existing email, I want to return 409 from my API. Now I return 500 because I cannot differentiate between a unique constraint error and normal error. I don't want to make another call to the database just to check if a user with that email already exists. I don't want to parse the error as string and pattern match for 'duplicate key'. How to properly handle this case with the pgx driver?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions