I think it depends on the scope. In my opinion, some reasons for the refusal do not concern the consumer, and they must be registered in the service. On the other hand, there are times when the consumer must be informed about these reasons, so in addition to registering them, you must somehow indicate the cause of the error.
For example, suppose this is a very common use case for a user registration service. It is very likely that you will have a unique attribute that identifies the user (user descriptor, email address, etc.). This uniqueness must be performed by the service (and possibly also at the database level). Now, if the consumer is trying to register the user and he fails because the restriction has been violated, the consumer must be notified of these reasons (so that he can try another user descriptor). In most cases, failed checks fall into the same scenario.
If on the other hand there is some kind of internal problem with the database, the consumer should not be informed about the details (because it is the sole responsibility for the service, and it is not that the consumer can do anything at all).
Given this, I would say that in many cases, returning a boolean value is not enough. Therefore, having a ServiceResult type ServiceResult not seem like a bad idea. I'm not sure that I will include Exception . But perhaps you can create some kind of ServiceExpection specific to your service. Sometimes error codes are also suitable for this.
Juan Pablo Califano
source share