feat(database): Enable error translation in GORM configuration for better error handling

This commit is contained in:
SoXX 2024-08-13 14:00:36 +02:00
parent 9ad1df51cf
commit 71488dade9
2 changed files with 5 additions and 2 deletions

View File

@ -67,7 +67,9 @@ func Connect(ctx context.Context, config models.DatabaseConfig) error {
} }
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", config.Endpoint, config.Username, config.Password, config.Database, config.Port, localSSL, config.Timezone) dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", config.Endpoint, config.Username, config.Password, config.Database, config.Port, localSSL, config.Timezone)
sqlDB, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) sqlDB, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
TranslateError: true,
})
if err != nil { if err != nil {
return utils.HandleError(ctx, span, localLogger, err) return utils.HandleError(ctx, span, localLogger, err)
} }

View File

@ -80,7 +80,8 @@ func migrateDatabase(connectionString string) error {
func getGormDB(connectionString string) (*gorm.DB, error) { func getGormDB(connectionString string) (*gorm.DB, error) {
return gorm.Open(postgres.Open(connectionString), &gorm.Config{ return gorm.Open(postgres.Open(connectionString), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info), Logger: logger.Default.LogMode(logger.Info),
TranslateError: true,
}) })
} }