feat(database): Enable error translation in GORM configuration for better error handling
This commit is contained in:
parent
9ad1df51cf
commit
71488dade9
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ 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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user