| name | Flutter Error Handling |
|---|---|
| description | Functional error handling using Dartz and Either. |
| metadata | {"labels": ["error-handling", "dartz", "functional"], "triggers": {"files": ["lib/domain/**", "lib/infrastructure/**"], "keywords": ["Either", "fold", "Left", "Right", "Failure", "dartz"]}} |
Error Handling
Priority: P1 (HIGH)
Standardized functional error handling using dartz and freezed failures.
Implementation Guidelines
- Either Pattern: Return
Either<Failure, T>from repositories. No exceptions in UI/BLoC. - Failures: Define domain-specific failures using
@freezedunions. - Mapping: Infrastructure catches
Exceptionand returnsLeft(Failure). - Consumption: Use
.fold(failure, success)in BLoC to emit corresponding states. - Typed Errors: Use
left(Failure())andright(Value())fromDartz.
Reference & Examples
For Failure definitions and API error mapping: See references/REFERENCE.md.
Related Topics
layer-based-clean-architecture | bloc-state-management