Rest API Exception handling in Asp.net core using built-in middleware

Hello dear developers and software crafters!
How do you feel today?

Some time ago I was working on an API project that had to consume lots of micro services that had responses serialized in JSON. Since I was using async methods I was implementing the typical tuple success, Object methods.

Out of curiosity I asked developers from other teams how they handled the Rest response codes and exceptions while complaining about the verbosity of my solution. Then after many shrugs a colleague told mi about Asp.net core middleware to trap exceptions.

Here is a piece on the subject that explains the process

https://blogs.msdn.microsoft.com/brandonh/2017/07/31/using-middleware-to-trap-exceptions-in-asp-net-core/

I hope you enjoy this piece as much as I did.

Happy coding and remember… there is life beyond coding 😊