diff --git a/internal/kurious/adapters/sqlite_learning_category_repository.go b/internal/kurious/adapters/sqlite_learning_category_repository.go index b3e9572..f65e6db 100644 --- a/internal/kurious/adapters/sqlite_learning_category_repository.go +++ b/internal/kurious/adapters/sqlite_learning_category_repository.go @@ -8,6 +8,7 @@ import ( "log/slog" "strings" + cerrors "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/xslices" "git.loyso.art/frx/kurious/internal/kurious/domain" @@ -156,7 +157,7 @@ func (r *sqliteLearingCategoryRepository) Get(ctx context.Context, id string) (c err = r.db.GetContext(ctx, &cdb, query, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return domain.LearningCategory{}, domain.ErrNotFound + return domain.LearningCategory{}, cerrors.ErrNotFound } return domain.LearningCategory{}, fmt.Errorf("executing query: %w", err) } diff --git a/internal/kurious/adapters/sqlite_learning_category_repository_test.go b/internal/kurious/adapters/sqlite_learning_category_repository_test.go index 9038cc3..0e5c8c9 100644 --- a/internal/kurious/adapters/sqlite_learning_category_repository_test.go +++ b/internal/kurious/adapters/sqlite_learning_category_repository_test.go @@ -3,6 +3,7 @@ package adapters import ( "testing" + "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/nullable" "git.loyso.art/frx/kurious/internal/kurious/domain" @@ -75,7 +76,7 @@ func (s *sqliteLearningCategoriesRepositorySuite) TestUpsert() { const categoryID = "test-id-1" repo := s.connection.LearningCategory() gotCategory, err := repo.Get(s.ctx, categoryID) - s.ErrorIs(err, domain.ErrNotFound) + s.ErrorIs(err, errors.ErrNotFound) s.Empty(gotCategory) createdCategory := domain.LearningCategory{ diff --git a/internal/kurious/adapters/sqlite_organization_repository.go b/internal/kurious/adapters/sqlite_organization_repository.go index 3ab2e9c..68132e4 100644 --- a/internal/kurious/adapters/sqlite_organization_repository.go +++ b/internal/kurious/adapters/sqlite_organization_repository.go @@ -9,6 +9,7 @@ import ( "strings" "time" + cerrors "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/xslices" "git.loyso.art/frx/kurious/internal/kurious/domain" "go.opentelemetry.io/otel/attribute" @@ -228,7 +229,7 @@ func (r *sqliteOrganizationRepository) Get(ctx context.Context, params domain.Ge err = r.db.GetContext(ctx, &orgdb, query, args...) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return out, domain.ErrNotFound + return out, cerrors.ErrNotFound } return out, fmt.Errorf("executing query: %w", err) } @@ -306,14 +307,14 @@ func (r *sqliteOrganizationRepository) Delete(ctx context.Context, id string) (e result, err := r.db.ExecContext(ctx, query, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return domain.ErrNotFound + return cerrors.ErrNotFound } return fmt.Errorf("executing query: %w", err) } affected, _ := result.RowsAffected() if affected == 0 { - return domain.ErrNotFound + return cerrors.ErrNotFound } return nil diff --git a/internal/kurious/domain/error.go b/internal/kurious/domain/error.go index ce3f41c..75fcac5 100644 --- a/internal/kurious/domain/error.go +++ b/internal/kurious/domain/error.go @@ -1,12 +1,8 @@ package domain -const ( - ErrNotFound PlainError = "not found" - ErrNotImplemented PlainError = "not implemented" +import ( + cerrors "git.loyso.art/frx/kurious/internal/common/errors" ) -type PlainError string - -func (err PlainError) Error() string { - return string(err) -} +// ErrNotImplemented is delegated to common/errors.ErrNotImplemented for consistency. +var ErrNotImplemented = cerrors.ErrNotImplemented diff --git a/internal/kurious/ports/http/server.go b/internal/kurious/ports/http/server.go index 10b5243..5b91266 100644 --- a/internal/kurious/ports/http/server.go +++ b/internal/kurious/ports/http/server.go @@ -9,7 +9,6 @@ import ( "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/xcontext" - "git.loyso.art/frx/kurious/internal/kurious/domain" "git.loyso.art/frx/kurious/internal/kurious/service" "git.loyso.art/frx/kurious/pkg/xdefault" @@ -50,7 +49,7 @@ func handleError(ctx context.Context, err error, w http.ResponseWriter, log *slo case stderrors.As(err, &valErr): errorString = valErr.Error() code = http.StatusBadRequest - case stderrors.Is(err, errors.ErrNotFound), stderrors.Is(err, domain.ErrNotFound): + case stderrors.Is(err, errors.ErrNotFound): errorString = err.Error() code = http.StatusNotFound default: