Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Do not throw exception on duplicate key constraint
Acho Arnold6cfc2ca14fed
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.goindex 2b4ceba4..b44ca9fd 100644--- a/api/pkg/di/container.go+++ b/api/pkg/di/container.go@@ -250,9 +250,9 @@ func (container *Container) DB() (db *gorm.DB) {container.logger.Debug(fmt.Sprintf("creating %T", db))- config := &gorm.Config{}+ config := &gorm.Config{TranslateError: true}if isLocal() {- config = &gorm.Config{Logger: container.GormLogger()}+ config.Logger = container.GormLogger()}db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), config)diff --git a/api/pkg/repositories/gorm_phone_repository.go b/api/pkg/repositories/gorm_phone_repository.goindex ca27179f..9d37c731 100644--- a/api/pkg/repositories/gorm_phone_repository.go+++ b/api/pkg/repositories/gorm_phone_repository.go@@ -5,11 +5,9 @@ import ("errors""fmt"- "github.com/google/uuid"- "gorm.io/gorm/clause"-"github.com/NdoleStudio/httpsms/pkg/entities""github.com/NdoleStudio/httpsms/pkg/telemetry"+ "github.com/google/uuid""github.com/palantir/stacktrace""gorm.io/gorm")@@ -80,11 +78,10 @@ func (repository *gormPhoneRepository) Save(ctx context.Context, phone *entitiesdefer span.End()err := repository.db.- Clauses(clause.OnConflict{DoNothing: true, OnConstraint: "idx__phones__user_id__phone_number"}).WithContext(ctx).Save(phone).Error- if err != nil {+ if err != nil && !errors.Is(err, gorm.ErrDuplicatedKey) {msg := fmt.Sprintf("cannot save phone with ID [%s]", phone.ID)return repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))}