Last post Apr 21, 2020 05:28 PM by PatriceSc
Apr 21, 2020 03:54 PM|first100|LINK
I'm working on refactor for some web API, I have a controller that receives some parameters, this controller sends everything to a service that has access to db, normally the service returns a collection of items or an empty list, here now I check that the
parameters are in some table, if there are, I can continue the execution, if I can't find them I have to go back and notify.
Here I would like to know what can be the best way to manage, I had thought of returning some (custom?) exceptions to the controller and the latter should be returning a bad request, but I am not convinced, the other way may be to return and object with
a list of items originally returned by the service with some other flag reporting the error.
In this case, I have to do a lot of refactoring work.
What do you think is the best way to manage this scenario?
Many thanks for the help.
Apr 21, 2020 05:28 PM|PatriceSc|LINK
So you rather have validation errors rather than a real exception?
You may want to have a look at ASP.NET Core even if not using it yet. For example it has https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.problemdetails?view=aspnetcore-3.1 based
on a RFC to return error details.
Still make sure to return application messages (not something that comes from an exception) and always take care of returning the proper http status.