eShopOnContainers icon indicating copy to clipboard operation
eShopOnContainers copied to clipboard

[Question] DomainExceptions don't bubble up when called through IdentifiedHandler

Open benbuckland opened this issue 4 years ago • 3 comments

Hi,

I am working through domain validations and handling of Domain Exceptions. If i'm not mistaken Domain Exceptions do not bubble up when the Domain Exception has been created from a call through IdentifiedCommandHandler. This appears to be due to exceptions being caught but no re thrown in the IdentifiedCommandHandler.cs :

catch { return default(R); }

Is this the intended behavior?

Many thanks.

benbuckland avatar Jun 10 '21 20:06 benbuckland

Hi @benbuckland, thank you for reaching out.

Any command handler class just focuses on processing the command. It doesn't focus on any domain-specific logic because it still stays within the Domain Model/Aggregated root. You may want to include all the domain validation logic in the constructor of the Domain Entity itself. For more details, refer to Design validations in the domain model layer

sughosneo avatar Jun 22 '21 15:06 sughosneo

Hi @sughosneo , thanks for coming back to me. Sorry my questions may not have been clear. My expectation is that any DomainExceptions will eventually bubble back to the caller (and returned through the API) but I'm not seeing that. The line of code I mentioned seems to be suppressing the exceptions from bubbling up or have I missed something?

benbuckland avatar Jun 22 '21 23:06 benbuckland

Hi @sughosneo any update on this? I have had a look at it again today and still cant figure it out.

benbuckland avatar Aug 30 '21 03:08 benbuckland