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:
@@ -142,3 +142,7 @@ const (
|
||||
const (
|
||||
ADD_INCIDENT_USER_MAPPING = "ADD_INCIDENT_USER_MAPPING"
|
||||
)
|
||||
|
||||
const (
|
||||
DUPLICATE_KEY_VALUE_ERROR_CODE = "23505"
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user