Error Handling and Validation Architecture in .NET Core

In many projects, error handling and validation are distributed across business logic, API controllers, and data access layers in the form of conditions (“if-else” sequences). This leads to the violation of the Separation of Concerns Principle and results in “Spaghetti code,” like in the example below.
….
if (user != null)
{
if (subscription != null)
{
if (term == Term.Annually)
{
// code 1
}
else if (term == Term.Monthly)
{
// code 2
}
else
{
throw new InvalidArgumentException(nameof(term));
}
}
else
{
throw new ArgumentNullException(nameof(subscription));
}
}
else
{
throw new ArgumentNullException(nameof(user));
}
…..
In this article, I describe an approach for sepearting validation and error handling logic from the other application layers.

Link: https://dzone.com/articles/error-handling-and-validation-architecture-in-net?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev