uniformed the error for duplicate key

This commit is contained in:
adragusin
2019-12-09 16:41:24 +02:00
parent 74ed5e9958
commit 4cf69dd552
6 changed files with 155 additions and 0 deletions

View File

@@ -879,6 +879,9 @@ func (self *SQLStorage) SetCDR(cdr *CDR, allowUpdate bool) error {
if saved.Error != nil {
tx.Rollback()
if !allowUpdate {
if strings.Contains(saved.Error.Error(), "1062") || strings.Contains(saved.Error.Error(), "duplicate key") { // returns 1062/pq when key is duplicated
return utils.ErrExists
}
return saved.Error
}
tx = self.db.Begin()