mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-22 02:06:39 +00:00
review comments
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/rs/xid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -5411,11 +5412,23 @@ func (s *SqlStore) SaveProxy(ctx context.Context, p *proxy.Proxy) error {
|
||||
result := s.db.WithContext(ctx).Save(p)
|
||||
if result.Error != nil {
|
||||
log.WithContext(ctx).Errorf("failed to save proxy: %v", result.Error)
|
||||
return status.Errorf(status.Internal, "failed to save proxy: %v", result.Error)
|
||||
if isUniqueConstraintError(result.Error) {
|
||||
return proxy.ErrAccountProxyAlreadyExists
|
||||
}
|
||||
return status.Errorf(status.Internal, "failed to save proxy")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isUniqueConstraintError(err error) bool {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
|
||||
return true
|
||||
}
|
||||
errStr := err.Error()
|
||||
return strings.Contains(errStr, "UNIQUE constraint") || strings.Contains(errStr, "duplicate key")
|
||||
}
|
||||
|
||||
// DisconnectProxy updates only the status, disconnected_at, and last_seen fields
|
||||
func (s *SqlStore) DisconnectProxy(ctx context.Context, proxyID string) error {
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user