Return conflict when removing a referenced person
Deleting a profile still referenced elsewhere (for example as an asset owner) surfaced an internal error. PostgreSQL reports ON DELETE RESTRICT blocks as SQLSTATE 23001, not 23503; map both in profile delete and propagate ErrProfileInUse through removeUser as CONFLICT. Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
committed by
Bryan Frimin
parent
9e47aba2b6
commit
888fa4d63a
@@ -323,7 +323,7 @@ WHERE %s AND id = @id
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23503" {
|
||||
if pgErr.Code == "23503" || pgErr.Code == "23001" {
|
||||
return ErrResourceInUse
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user