Get the source code for this video for FREE → the-dotnet-weekly.ck.page/global-errors Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@@MilanJovanovicTech hello Milan, I'm happy to say I passed my technical and got a job with #1 shop in my country! Knowledge I got from your video about caching and Redis was probably the defining point. Thank you very much! You get a new long-term patreon sub as my gratitude!
Dear Milan, thank you for the amazing video. One thing that got me wondering was the Idea of multiple ExceptionHandlers, as you mentioned in your video. How could one ensure a specific order in which these Handlers would be invoqued in case of an Exception that came from an Endpoint from your controller? Ideally, I would suggest to always keep a GlobalExceptionHandler (just like the one you implemented in this video), plus any other specific Exception Handler. I thank you for your time, and I hope to hear from you soon.
Hey, Milan. Great work on your channel. Quick question. Why would we need a middleware or implementing a custom IExceptionHandler in order to have logging and problem details for internal server errors? Isn't the default UseExceptionHandler middleware doing this already? Thanks, respect!
@@MilanJovanovicTech That explains it, I was trying to use it in a function APP, btw I sent you an answer on Linkedin, hope you have not become to famous to answer? But I guess you just have a lot to do these days
i have got a problem, i am using sth similar to what you are doing for middleware, but my methods are called by background tasks done with quartz jobs. If i am calling the method manually from swagger/postmen it works, but with jobs doesn t
Good job. One question, why did you name the folder as /Infrastructure inside the Api project and not other name, like: /ExceptionHandlers? The old and traditional Middlewares you have put inside /Middlewares folder. And finally, in a real project using some layered architecture, would you put this implementation inside Infra layer or Presentation (where the WebApi resides) layer? 🤔
Hey, Milan! A little bit off-topic, but could you tell how I can map List classIds instead of List classes in an aggregate root (is it even possible)? I have 2 aggregates with one-to-many relationship. I heard Aggregates can have only id references to other aggregates. I get errors trying to create a migration with ef core.
Thank you, Milan! Always Good Technical Video Post. I have one question. How to handle unauthorized controller in global. How to all generic message display error or status code wise?
But The problem is i need to log the exception that occured on each endpoint in to a specific database table along with the request parameters and exception, so if i catch the exception globally how do i differentiate between the origin of the exception and where do i write the logic of the logging. in the middleware ?
tks. Am I correct that when the Global-EH returns true, even if it is last in the middleware chain then its response by-passes all previous/before middlewares and it goes directly back to the client?
to automatically convert different errors (bad request, conflict, not found) to a problem details will you introduce the status code param to the error object and create different problem details instance which will be mapped depending on the error status codes? or there is a simpler way to implement this?
I'm interested in making videos like you do, but I have some reservations. I'm worried about potentially making mistakes, or not covering topics thoroughly or in an unusual manner. Do you have any advice for getting started and overcoming these fears? I understand that everyone errs occasionally, but it seems to be the main obstacle holding me back. Even though I'm not afraid of making mistakes on my work and other aspect of my life, but when it comes to teaching, it's just ah..
Get the source code for this video for FREE → the-dotnet-weekly.ck.page/global-errors
Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
Yay code giveaway
Very nice! Short, concise and very useful - keep up the excellent work, Milan.
Glad you liked it!
Thank you, Milan! Always up-to-date, I learned a lot from you in last month which helped me on my interviews!
How did the interviews go? 😁
@@MilanJovanovicTech still waiting for last circles, but so far - not bad :)
@@MilanJovanovicTech hello Milan, I'm happy to say I passed my technical and got a job with #1 shop in my country! Knowledge I got from your video about caching and Redis was probably the defining point. Thank you very much! You get a new long-term patreon sub as my gratitude!
@@f.d.9326 I'm thrilled for you! Keep crushing it 🔥🔥
Thank you mam.
Content is Perfect balance between very technical, useful and just about the right amount of watching time.
Keep 'em rolling
Thanks a lot 😊
Dear Milan, thank you for the amazing video. One thing that got me wondering was the Idea of multiple ExceptionHandlers, as you mentioned in your video. How could one ensure a specific order in which these Handlers would be invoqued in case of an Exception that came from an Endpoint from your controller? Ideally, I would suggest to always keep a GlobalExceptionHandler (just like the one you implemented in this video), plus any other specific Exception Handler.
I thank you for your time, and I hope to hear from you soon.
They are called in order of registration
Is there ultimately any benefit of choosing one Vs the other approach?
Chaining exception handlers: www.milanjovanovic.tech/blog/global-error-handling-in-aspnetcore-8#chaining-exception-handlers
Hey, Milan. Great work on your channel.
Quick question. Why would we need a middleware or implementing a custom IExceptionHandler in order to have logging and problem details for internal server errors? Isn't the default UseExceptionHandler middleware doing this already? Thanks, respect!
It is, but I prefer taking control of this using my own
Which validations should I run on the use cases, and which ones should I run on the domain?
Input validation - before use case
Business rules - use case or domain (you decide)
Nice video as always my friend! In which place did you put the ProblemDetails class?
It's a built-in class
@@MilanJovanovicTech from which Library?
I would guess you have imported a nuget package of some sort, or it is coming from some .NET core stuff? didnt know about this.
@@nicolaimagnussen1914 ASP .NET
@@MilanJovanovicTech That explains it, I was trying to use it in a function APP, btw I sent you an answer on Linkedin, hope you have not become to famous to answer? But I guess you just have a lot to do these days
i have got a problem, i am using sth similar to what you are doing for middleware, but my methods are called by background tasks done with quartz jobs. If i am calling the method manually from swagger/postmen it works, but with jobs doesn t
Middleware only work during the HTTP request pipeline - you'll have to add error handling yourself for background jobs
How to use this approach when we are using controllers ( not minimal api)
Works exactly the same
Hi Milan, I have .net 8 but my VS not recognize IExceptionHandler and his namespace. Can you give me some pointers?
No idea, it should be working on .NET 8 without any issues
Hi, where can i access the code you used in the demonstration please?. Great video!
It's available on Patreon, check the video description
Hi Milan, great video, but how should I create a exception filter to handle API errors in caller api project, for example blazor?
Http Client? Delegating Handlers?
@@MilanJovanovicTech yes, but should I control status codes and log them? In my case I return problem details
Hi Milan, in the MVC Web Application, how to display the error message to view (/Home/Error)?
No idea, haven't touched MVC in ages
Hey Milan, what extension are you using for inline debug variable/parameter info?
ReSharper
Good job.
One question, why did you name the folder as /Infrastructure inside the Api project and not other name, like: /ExceptionHandlers?
The old and traditional Middlewares you have put inside /Middlewares folder.
And finally, in a real project using some layered architecture, would you put this implementation inside Infra layer or Presentation (where the WebApi resides) layer? 🤔
Two hard things in software engineering...
Is this valid for webapps that work with blazor or just for web apis?
No idea, I don't use Blazor
Hey, Milan! A little bit off-topic, but could you tell how I can map List classIds instead of List classes in an aggregate root (is it even possible)? I have 2 aggregates with one-to-many relationship. I heard Aggregates can have only id references to other aggregates. I get errors trying to create a migration with ef core.
Why complicate your life like that? 😁
@@MilanJovanovicTech You suggest reference classes instead of their ids? It's OK?
Thank you, Milan! Always Good Technical Video Post. I have one question. How to handle unauthorized controller in global. How to all generic message display error or status code wise?
I'm not sure what exactly you're asking here
@@MilanJovanovicTech How to handle [Authorize] above write in controller in global error handling?
But The problem is i need to log the exception that occured on each endpoint in to a specific database table along with the request parameters and exception, so if i catch the exception globally how do i differentiate between the origin of the exception and where do i write the logic of the logging. in the middleware ?
Use a Serilog sink for that, easier
Is there a reason to use the IExceptionHandler instead of simply implementing your own middleware?
Just an alternative, no compelling reason other than being able to stack multiple IExceptionHandlers for different exception types
Beautiful
Thank you!
Thank you. I like that this feature. 🤩
You’re welcome 😊
Does anyone how does he do to remove all the using statements and also set the class to public in Visual Studio? I can't find a way to do it 😭😭
It's some Visual Studio and ReSharper cleanup functions
IDateTimeProvider realization?
Hmm?
In swagger I sent an invalid json (without last bracket) and this code not activated and I got a generic error....
Oh
@@MilanJovanovicTech ? 😀 did you tested?
Can repository return Result object?
Yes
Very helpful, thanks
You're welcome!
tks. Am I correct that when the Global-EH returns true, even if it is last in the middleware chain then its response by-passes all previous/before middlewares and it goes directly back to the client?
Yes - it short circuits
to automatically convert different errors (bad request, conflict, not found) to a problem details will you introduce the status code param to the error object and create different problem details instance which will be mapped depending on the error status codes? or there is a simpler way to implement this?
Yes, add a status to Error and then map that to ProblemDetails
thanks
You're welcome! :)
I'm interested in making videos like you do, but I have some reservations. I'm worried about potentially making mistakes, or not covering topics thoroughly or in an unusual manner. Do you have any advice for getting started and overcoming these fears? I understand that everyone errs occasionally, but it seems to be the main obstacle holding me back. Even though I'm not afraid of making mistakes on my work and other aspect of my life, but when it comes to teaching, it's just ah..
Just start, friend. Let your audience tell you if you made mistakes. Accept them, and try to do better next video. Nobody is perfect.
Thank you for a great video!
Milan, can you share this project source code for the convenience, please?
It's shared on Patreon. Some example here: www.milanjovanovic.tech/blog/global-error-handling-in-aspnetcore-8
@@MilanJovanovicTech Missed that link, thanks :)
thank you very much
You are welcome
Quality stuff ! keep it up
Thanks!
Milan looks to be losing his sanity after every thumbnail😅
Nah, still hanging on 😁
🏆