···
// 3. This avoids a race condition where two concurrent requests both pass the check
recordURI, recordCID, err := s.createRecordOnPDSAs(ctx, userDID, "social.coves.community.block", "", blockRecord, userAccessToken)
557
-
// Check if this is a duplicate error from PDS
557
+
// Check if this is a duplicate/conflict error from PDS
558
+
// PDS should return 409 Conflict for duplicate records, but we also check common error messages
559
+
// for compatibility with different PDS implementations
559
-
if strings.Contains(errMsg, "duplicate") || strings.Contains(errMsg, "already exists") {
561
+
isDuplicate := strings.Contains(errMsg, "status 409") || // HTTP 409 Conflict
562
+
strings.Contains(errMsg, "duplicate") ||
563
+
strings.Contains(errMsg, "already exists") ||
564
+
strings.Contains(errMsg, "AlreadyExists")
// Fetch and return existing block from our indexed view
existingBlock, getErr := s.repo.GetBlock(ctx, userDID, communityDID)
···
return "", ErrInvalidInput
655
-
// If it's already a DID, return it
662
+
// If it's already a DID, verify the community exists
if strings.HasPrefix(identifier, "did:") {
664
+
_, err := s.repo.GetByDID(ctx, identifier)
666
+
if IsNotFound(err) {
667
+
return "", fmt.Errorf("community not found: %w", err)
669
+
return "", fmt.Errorf("failed to verify community DID: %w", err)