Senior
Why do you put business errors (ErrUnknownRoom, ErrRoomNotAvailable) into the domain layer?
sobes.tech AI
Answer from AI
Carrying business errors (for example, ErrUnknownRoom, ErrRoomNotAvailable) into the domain layer allows:
- Clearly separating business logic from infrastructural details and technical errors.
- Ensuring a uniform and understandable representation of errors related to business rules.
- Simplifying error handling at the application level, as domain errors reflect specific business states.
- Improving code readability and maintainability, as errors become part of the domain model.
For example, if ErrRoomNotAvailable is returned in the domain layer, it clearly indicates that the room is occupied, and the calling code can make decisions based on business logic rather than technical details of the database or network.