Global Exception Handling in .Net Core Clean Architecture - Part 8

CodeWithHanif
CodeWithHanif
1.3 هزار بار بازدید - 9 ماه پیش - In this Video, we will
In this Video, we will learn about Global Exception Handling in ASP.NET Core applications. Exceptions are something inevitable in any application however well the codebase is. This can usually occur due to external factors as well, like network issues and so on. If these exceptions are not handled well within the application, it may even lead the entire application to terminations and data loss.

We will also be creating Custom Exception classes that can essentially make your application throw more sensible exceptions that can be easily understood.

But before that, build a Response class that I recommend to be a part of every project you build, at least the concept. So, the idea is to make your ASP.NET Core API send uniform responses no matter what kind of requests it gets hit with. This make the work easier for whoever is consuming your API. Additionally it gives a much experience while developing.

The ApiResponse class is of a generic type, meaning any kind of data can be passed along with it. Data property will hold the actual data returned from the server. Message contains any Exceptions or Info message in string type. And finally there is a boolean that denotes if the request is a success. You can add multiple other properties as well depending on your requirement.

We also have Fail and Success method that is built specifically for our Exception handling scenario. You can find how this is being used in the upcoming sections.
#cleanarchitecture
#dotnetcore

Table of contents:
0:00 - Global Exception Handling in .Net Core introduction
09:53 - Custom ApiException
16:20 - Custom ApiResponse class to send uniform responses
34:37 - Fluent Validation custom class to catch errors

Source Code:
https://github.com/huzaifa21718/Clean...
9 ماه پیش در تاریخ 1402/08/05 منتشر شده است.
1,307 بـار بازدید شده
... بیشتر