Ограничить ожидание зависимостей и отвечать 503 при их недоступности

This commit is contained in:
2026-10-06 15:13:04 +03:00
parent 9890482747
commit f6acdf91e0
10 changed files with 313 additions and 21 deletions
+6 -4
View File
@@ -1,4 +1,6 @@
// Package store holds the repository implementations of the users module.
// Errors pass through postgres.Classify, so an unreachable database surfaces
// as unavailability rather than as an internal error.
package store
import (
@@ -36,7 +38,7 @@ func (r *Users) Create(ctx context.Context, u user.User) error {
return user.ErrUsernameTaken
}
if err != nil {
return fmt.Errorf("insert user: %w", err)
return fmt.Errorf("insert user: %w", postgres.Classify(err))
}
return nil
}
@@ -52,11 +54,11 @@ func (r *Users) GetByUsername(ctx context.Context, username string) (user.User,
func (r *Users) ExistingIDs(ctx context.Context, ids []uuid.UUID) ([]uuid.UUID, error) {
rows, err := r.pool.Query(ctx, `SELECT id FROM users WHERE id = ANY($1)`, ids)
if err != nil {
return nil, fmt.Errorf("select user ids: %w", err)
return nil, fmt.Errorf("select user ids: %w", postgres.Classify(err))
}
found, err := pgx.CollectRows(rows, pgx.RowTo[uuid.UUID])
if err != nil {
return nil, fmt.Errorf("read user ids: %w", err)
return nil, fmt.Errorf("read user ids: %w", postgres.Classify(err))
}
return found, nil
}
@@ -68,7 +70,7 @@ func (r *Users) one(ctx context.Context, query string, arg any) (user.User, erro
return user.User{}, user.ErrNotFound
}
if err != nil {
return user.User{}, fmt.Errorf("select user: %w", err)
return user.User{}, fmt.Errorf("select user: %w", postgres.Classify(err))
}
u.CreatedAt = u.CreatedAt.UTC()
return u, nil