GORM: How to check if an error is of type Duplicate Key
June 10, 2023If you have an unique index on a table and try to to insert duplicate records in that table you get a Duplicate key violation error. You can handle this error more gracefully by capturing it. If you are using GORM in Golang, then you can easily check if an error is of type Duplicate Key.