The New Global Error Handling in ASP.NET Core 8

Поделиться
HTML-код
  • Опубликовано: 24 авг 2024

Комментарии • 95

  • @MilanJovanovicTech
    @MilanJovanovicTech  8 месяцев назад +1

    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

  • @MrAlkazam
    @MrAlkazam 7 месяцев назад +4

    Very nice! Short, concise and very useful - keep up the excellent work, Milan.

  • @f.d.9326
    @f.d.9326 8 месяцев назад +1

    Thank you, Milan! Always up-to-date, I learned a lot from you in last month which helped me on my interviews!

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад

      How did the interviews go? 😁

    • @f.d.9326
      @f.d.9326 8 месяцев назад

      @@MilanJovanovicTech still waiting for last circles, but so far - not bad :)

    • @f.d.9326
      @f.d.9326 8 месяцев назад +1

      @@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!

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад

      @@f.d.9326 I'm thrilled for you! Keep crushing it 🔥🔥

  • @Targeting-Must-End
    @Targeting-Must-End 8 месяцев назад +2

    Thank you mam.
    Content is Perfect balance between very technical, useful and just about the right amount of watching time.
    Keep 'em rolling

  • @philiperiskallaleal6010
    @philiperiskallaleal6010 2 месяца назад

    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.

  • @W1ese1
    @W1ese1 8 месяцев назад +2

    Is there ultimately any benefit of choosing one Vs the other approach?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад +2

      Chaining exception handlers: www.milanjovanovic.tech/blog/global-error-handling-in-aspnetcore-8#chaining-exception-handlers

  • @zdxzxzdxzx6780
    @zdxzxzdxzx6780 6 месяцев назад +1

    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
      @MilanJovanovicTech  6 месяцев назад

      It is, but I prefer taking control of this using my own

  • @alexramossilva
    @alexramossilva 8 месяцев назад +1

    Which validations should I run on the use cases, and which ones should I run on the domain?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад

      Input validation - before use case
      Business rules - use case or domain (you decide)

  • @nicolaimagnussen1914
    @nicolaimagnussen1914 6 месяцев назад +1

    Nice video as always my friend! In which place did you put the ProblemDetails class?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 месяцев назад +1

      It's a built-in class

    • @nicolaimagnussen1914
      @nicolaimagnussen1914 6 месяцев назад

      @@MilanJovanovicTech from which Library?

    • @nicolaimagnussen1914
      @nicolaimagnussen1914 6 месяцев назад

      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.

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 месяцев назад

      @@nicolaimagnussen1914 ASP .NET

    • @nicolaimagnussen1914
      @nicolaimagnussen1914 6 месяцев назад

      @@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

  • @dariusghita9214
    @dariusghita9214 8 месяцев назад +1

    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

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад

      Middleware only work during the HTTP request pipeline - you'll have to add error handling yourself for background jobs

  • @nirajchandrajoshi
    @nirajchandrajoshi 5 месяцев назад +1

    How to use this approach when we are using controllers ( not minimal api)

  • @davide1486566555
    @davide1486566555 7 месяцев назад +1

    Hi Milan, I have .net 8 but my VS not recognize IExceptionHandler and his namespace. Can you give me some pointers?

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

      No idea, it should be working on .NET 8 without any issues

  • @shazaddin1
    @shazaddin1 8 месяцев назад +1

    Hi, where can i access the code you used in the demonstration please?. Great video!

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад

      It's available on Patreon, check the video description

  • @alfonsdeda8912
    @alfonsdeda8912 7 месяцев назад +1

    Hi Milan, great video, but how should I create a exception filter to handle API errors in caller api project, for example blazor?

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

      Http Client? Delegating Handlers?

    • @alfonsdeda8912
      @alfonsdeda8912 7 месяцев назад

      @@MilanJovanovicTech yes, but should I control status codes and log them? In my case I return problem details

  • @sky3913
    @sky3913 2 месяца назад

    Hi Milan, in the MVC Web Application, how to display the error message to view (/Home/Error)?

  • @sigtrygguradv
    @sigtrygguradv 8 месяцев назад +1

    Hey Milan, what extension are you using for inline debug variable/parameter info?

  • @haraheiquedossantos4283
    @haraheiquedossantos4283 3 месяца назад

    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? 🤔

  • @john1455
    @john1455 8 месяцев назад +1

    Is this valid for webapps that work with blazor or just for web apis?

  • @ZubriQue
    @ZubriQue 8 месяцев назад +1

    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.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад +2

      Why complicate your life like that? 😁

    • @ZubriQue
      @ZubriQue 8 месяцев назад

      @@MilanJovanovicTech You suggest reference classes instead of their ids? It's OK?

  • @achalprajapati1192
    @achalprajapati1192 17 дней назад

    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?

    • @MilanJovanovicTech
      @MilanJovanovicTech  16 дней назад

      I'm not sure what exactly you're asking here

    • @achalprajapati1192
      @achalprajapati1192 16 дней назад

      @@MilanJovanovicTech How to handle [Authorize] above write in controller in global error handling?

  • @nabeegh8766
    @nabeegh8766 5 месяцев назад

    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 ?

  • @crutz3064
    @crutz3064 4 месяца назад

    Is there a reason to use the IExceptionHandler instead of simply implementing your own middleware?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 месяца назад

      Just an alternative, no compelling reason other than being able to stack multiple IExceptionHandlers for different exception types

  • @deepakdutta2879
    @deepakdutta2879 3 месяца назад +1

    Beautiful

  • @taner-saydam
    @taner-saydam 8 месяцев назад

    Thank you. I like that this feature. 🤩

  • @juanpaoc1728
    @juanpaoc1728 Месяц назад

    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 😭😭

    • @MilanJovanovicTech
      @MilanJovanovicTech  Месяц назад +1

      It's some Visual Studio and ReSharper cleanup functions

  • @user-xm7sh3vw8o
    @user-xm7sh3vw8o 8 месяцев назад +1

    IDateTimeProvider realization?

  • @pitthp
    @pitthp 4 месяца назад

    In swagger I sent an invalid json (without last bracket) and this code not activated and I got a generic error....

  • @akashkarve1991
    @akashkarve1991 5 месяцев назад

    Can repository return Result object?

  • @YehorBachurinDev
    @YehorBachurinDev 5 месяцев назад

    Very helpful, thanks

  • @pigrebanto
    @pigrebanto 6 месяцев назад

    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?

  • @ahmedrizk106
    @ahmedrizk106 8 месяцев назад

    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?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад +1

      Yes, add a status to Error and then map that to ProblemDetails

  • @mohamadmmm1481
    @mohamadmmm1481 8 месяцев назад +1

    thanks

  • @LilPozzer
    @LilPozzer 8 месяцев назад

    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..

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад +2

      Just start, friend. Let your audience tell you if you made mistakes. Accept them, and try to do better next video. Nobody is perfect.

  • @AzWatchYT
    @AzWatchYT 8 месяцев назад +1

    Thank you for a great video!
    Milan, can you share this project source code for the convenience, please?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 месяцев назад

      It's shared on Patreon. Some example here: www.milanjovanovic.tech/blog/global-error-handling-in-aspnetcore-8

    • @AzWatchYT
      @AzWatchYT 8 месяцев назад

      @@MilanJovanovicTech Missed that link, thanks :)

  • @lasindunuwanga5292
    @lasindunuwanga5292 8 месяцев назад

    thank you very much

  • @leulgirma
    @leulgirma 4 месяца назад

    Quality stuff ! keep it up

  • @UnleashedDan
    @UnleashedDan 8 месяцев назад

    Milan looks to be losing his sanity after every thumbnail😅

  • @techpc5453
    @techpc5453 8 месяцев назад