INFRA-3661 : Filter out errors for duplicate key value pairs (#450)

* INFRA-3661 : Filter out errors for duplicate key value pairs

* INFRA-3661 : PR review changes

* INFRA-3611 : Remove whitespace
This commit is contained in:
Vijay Joshi
2024-08-12 17:25:26 +05:30
committed by GitHub
parent 62d65862b7
commit a10d71aaea
2 changed files with 15 additions and 2 deletions

View File

@@ -142,3 +142,7 @@ const (
const (
ADD_INCIDENT_USER_MAPPING = "ADD_INCIDENT_USER_MAPPING"
)
const (
DUPLICATE_KEY_VALUE_ERROR_CODE = "23505"
)

View File

@@ -1,7 +1,12 @@
package incidentUser
import (
"errors"
"fmt"
"github.com/jackc/pgx/v5/pgconn"
"gorm.io/gorm"
"houston/common/util"
"houston/logger"
"houston/model/incidentUser"
)
@@ -16,10 +21,14 @@ func (repo *incidentUserRepositoryImpl) AddIncidentUser(incidentId uint, userId
})
if result.Error != nil {
return result.Error
logger.Error(fmt.Sprintf("failed to add incident-user mapping with incidentId %d and userId %d: %v", incidentId, userId, result.Error))
var pgErr *pgconn.PgError
if errors.As(result.Error, &pgErr) && pgErr.Code == util.DUPLICATE_KEY_VALUE_ERROR_CODE {
return nil
}
}
return nil
return result.Error
}
func (repo *incidentUserRepositoryImpl) RemoveIncidentUser(incidentId uint, userId uint) error {