fix(events): a delete blocked by a restricting reference answers 409 (#2062)

This commit is contained in:
sam committed 2026-11-22 11:46:02 +11:00
1 parent 61f576a25c
commit 501338ffbd
1 file changed
+4 -1
+4 -1
View File
@@ -19,7 +19,10 @@ var ErrInUse = errors.New("in use")
// ErrExists means a row with that name already exists.
var ErrExists = errors.New("already exists")
// Postgres reports a delete blocked by ON DELETE RESTRICT as 23001 and a
// reference to a missing row as 23503.
const (
restrictViolation = "23001"
foreignKeyViolation = "23503"
uniqueViolation = "23505"
)
@@ -29,7 +32,7 @@ const (
func classify(err error) error {
if pqErr, ok := errors.AsType[*pgconn.PgError](err); ok {
switch pqErr.Code {
case foreignKeyViolation:
case restrictViolation, foreignKeyViolation:
return fmt.Errorf("%w: %s", ErrInUse, pqErr.Detail)
case uniqueViolation:
return ErrExists