Skip to content

Conversation

@marcuscastelo
Copy link
Owner

This PR standardizes error handling and user feedback in the application layer for multiple modules, including user, search-cache, day-diet, meal, food, macro-profile, recent-food, measure, recipe, and item-group. All application layer orchestrations now consistently use handleApiError with context, and UI feedback is unified via showPromise where appropriate. Domain logic is kept pure, and error throwing is enforced in repositories. Validation and error propagation are improved, especially in recipe and food modules. The PR also includes a new documentation file outlining the application layer error handling plan.

Notable changes:

  • Application layer functions now always call handleApiError with context.
  • Domain code no longer uses handleApiError.
  • UI feedback is standardized using showPromise.
  • Improved validation and error propagation in repositories.
  • Documentation added: docs/application-layer-error-handling-plan.md.

closes #307

…in fetchDayDiet

- fetchDayDiet now throws on error or not found, never returns null
- uses handleApiError and handleValidationError with context
- updated JSDoc for exported function
- all checks and tests passed
…upabaseFoodRepository

- fetchFoodById, fetchFoodByEan, insertFood, upsertFood now throw on error or not found, never return null
- use handleApiError with context for all error cases
- updated JSDoc for all exported functions
- all checks and tests passed
… supabaseRecipeRepository

- All exported functions now throw on error or not found, never return null
- All error cases use handleApiError with context
- Updated JSDoc for all exported functions
- All checks and tests passed
…ProfileRepository

- All exported functions now throw errors instead of returning null
- Use handleApiError for API/validation errors
- Add and update JSDoc for all exported functions
- Remove all null returns for error cases
- Ensure code passes lint, type-check, and tests
… toast display

- Adiciona try/catch em todos os parseWithStack/map(createRecipeFromDAO)
- Chama handleValidationError para erros de validação de schema
- Garante que erros de validação apareçam corretamente no toast
- Passa lint, type-check e testes
…ience and never throw to UI

- Usa showPromise com { context, audience } em todas as operações
- Nunca propaga erro para a UI, sempre retorna valor seguro
- Garante tratamento consistente de erros com handleApiError
- Passa lint, type-check e testes
Copilot AI review requested due to automatic review settings June 10, 2025 09:27
@marcuscastelo marcuscastelo self-assigned this Jun 10, 2025
@vercel
Copy link

vercel bot commented Jun 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marucs-diet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 6:24pm

@github-actions github-actions bot added improvement Technical debt or general improvement todo 🗒️ labels Jun 10, 2025

This comment was marked as outdated.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request standardizes error handling and user feedback across multiple modules by consistently using handleApiError and showPromise. Key changes include updating application layer functions in user, food, recipe, day-diet, and macro-profile modules, as well as adding detailed documentation for the error handling plan.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/sections/item-group/components/GroupHeaderActions.tsx Adds a check to handle missing insertedRecipe with a UI error message.
src/modules/user/application/user.ts Updates fetch, insert, update, and delete operations to return explicit boolean or null values and use showPromise.
src/modules/search/application/searchCache.ts Standardizes return values for caching functions with error handling via handleApiError.
src/modules/recent-food/application/recentFood.ts Wraps recent food operations in showPromise and improves error reporting.
src/modules/measure/application/measure.ts Updates measure functions to return null/boolean on errors with standardized error handling.
src/modules/diet/recipe/infrastructure/supabaseRecipeRepository.ts Refactors recipe repository functions to include validation error handling and consistent error feedback.
src/modules/diet/recipe/application/recipe.ts Applies showPromise to user recipe functions for improved UI feedback.
src/modules/diet/meal/application/meal.ts Updates meal update functions to return boolean instead of throwing errors.
src/modules/diet/macro-profile/infrastructure/supabaseMacroProfileRepository.ts Standardizes macro profile operations with detailed error and validation handling.
src/modules/diet/macro-profile/application/macroProfile.ts Adjusts macro profile functions to return explicit values on failure and use showPromise.
src/modules/diet/item-group/domain/itemGroup.ts Updates the schema by removing the non-empty constraint from items.
src/modules/diet/food/infrastructure/supabaseFoodRepository.ts Refactors food repository functions with upsert and detailed error handling.
src/modules/diet/food/application/food.ts Enhances food search functions and integrates caching logic with improved error reporting.
src/modules/diet/day-diet/infrastructure/supabaseDayRepository.ts Improves fetching a day diet with detailed error and validation handling.
src/modules/diet/day-diet/application/dayDiet.ts Adjusts day diet operations to return a boolean result and updates error handling accordingly.
Comments suppressed due to low confidence (2)

src/modules/diet/day-diet/application/dayDiet.ts:140

  • The return type for updateDayDiet has changed from void to boolean. Verify that all consumers of this function have been updated to handle its new boolean return value.
): Promise<boolean> {

src/modules/diet/day-diet/infrastructure/supabaseDayRepository.ts:69

  • The function calls handleValidationError but the file does not import it. Please add an appropriate import for handleValidationError to ensure proper error reporting.
handleValidationError('DayDiet not found', {

@marcuscastelo marcuscastelo merged commit 72f8bc2 into rc/v0.11.0 Jun 10, 2025
5 checks passed
@marcuscastelo marcuscastelo deleted the marcuscastelo/issue307 branch June 10, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Technical debt or general improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

better error handling

2 participants