Files
mtusi2026lab7/internal/postgres/errors.go
T
sxdees 2f2047909f
Skeleton contracts / contracts (pull_request) Blocked by required conditions
ЛР7 на 4: HTTPS, mTLS, OpenBao AppRole и ротация leaf.
Smoke/security/grade4/persistence/failover пройдены; REPORT и DEFENSE.
2026-12-02 23:08:27 +03:00

26 lines
421 B
Go

package postgres
import (
"errors"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
const (
CodeUniqueViolation = "23505"
CodeForeignKeyViolation = "23503"
CodeCheckViolation = "23514"
)
func ErrCode(err error) string {
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
return pgErr.Code
}
return ""
}
func IsNotFound(err error) bool {
return errors.Is(err, pgx.ErrNoRows)
}