When postgres sends an error, it sends a message with a code, example:
SQLSTATE [23505]: Unique violation: 7 ERROR: duplicate key violates uniqueness restriction «cargos_index_lower_unique» DETAIL: The key already exists (lower (name :: text)) = (Engineer). (SQL: insert into "cargos" ("name", "updated_at", "created_at") values (ingeNiero, 2016-11-08 11:07:58, 2016-11-08 11:07:58) returning "id ")
How can I get the value of "SQLSTATE [23505]"? Is there a parameter for the Exception where I can do that? Or do I have to separate everything else manually?