thombergs/buckpal

How does Exception Handling integrate into Clean Architecture?

tscz opened this issue · 0 comments

tscz commented

Hi @thombergs, thanks for a great book, it was really a great eye-opener to bring clean architecture into practice.

In general, I have problems to connect the dots in one topic: How does exception handling conceptionally fit into the picture?

For example the LoadAccountPort defines loadAccount interface/communication channel but the concrete adapter implementation throws an EntityNotFoundException if an account is not found. Instead of an implementation detail isn't this a property of the communication port, which all adapters of this port should comply with? Or asked the other way round, how can I force/lead implementeers of port interfaces to throw "expected" exceptions?

Another area where I am not sure about is global error handling: Say I want that the EntityNotFoundException should relate to a 404 and the service ThresholdExceededException should lead to a 403, both with a default error response body (i.e based on rfc7807). If I create now a global error handler in the web adapter, isn't then also the web adapter implementation depending on implementation details (EntityNotFoundException) of the implementation detail of another out adapter impl.?