fix(events): a delete blocked by a restricting reference answers 409 (#2062)
This commit is contained in:
1 file changed
+4
-1
@@ -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
|
||||
|
||||
Reference in new issue
Block a user