Global Error Handling | ASP.NET 6 REST API Following CLEAN ARCHITECTURE & DDD Tutorial | Part 4

Поділитися
Вставка
  • Опубліковано 25 сер 2024

КОМЕНТАРІ • 152

  • @kmcdo
    @kmcdo 2 роки тому +11

    Every time Copilot gives me what I want, I now can’t help but say “yeeesss?” Keep these videos coming; excellent content!

  • @MrFallout86
    @MrFallout86 11 місяців тому +3

    Just found your channel. Pure gold. I’ve been developing for 12 years, and I’ve never seen more precise content. Sometimes it’s great to see your own approaches validated and learn new ways of working and tools on the way

  • @TheFeljoy
    @TheFeljoy 2 роки тому +18

    Really enjoying this series. I already learned a few cool things and am looking forward to the DDD parts💪

  • @amantinband
    @amantinband  2 роки тому +32

    Really curios to hear what you thought of the video. Was diving into the framework's code useful? Would it have been better to only demonstrate the error endpoint with the factory instead of the various options?

    • @serkan.bircan
      @serkan.bircan 2 роки тому +7

      Very useful. And it was also clever to open the repo in dev-containers. 👏

    • @jamesevans6438
      @jamesevans6438 2 роки тому +5

      Another great video, thanks! I really liked the progressive approach and showing all the options, I think your content is for the more advanced developer who can appreciate that there are many tools available to solve a problem and can choose the right tool for the scenario. I’ve been using the Hellang library to create my problem details and that has some nice features also.

    • @amantinband
      @amantinband  2 роки тому +4

      @@gold15o2 In the next video we'll see a more practical example of how ProblemDetails can be used to represents one or more errors

    • @mcquiggd
      @mcquiggd 2 роки тому +3

      This is very good content, and the speed is perfect. Well explained, and as mentioned elsewhere, the progressive approach that shows the different approaches is very useful, please do continue to follow that pattern. Examining the Framework code is also useful - personally, that is how I investigate new technologies when they are released.
      There are already hundreds of channels that cover an introductory approach to the subject, so it's good to actually see content for established developers, that already know the basics but are interested in guidance / discussion. That is really an area that few people are targeting - Nick Chapsas is the only one who springs to mind, but he doesn't really do "real world applications", it's more specific technologies or language features.

    • @mcquiggd
      @mcquiggd 2 роки тому

      @@amantinband Perhaps including Validation errors.... maybe with both built-in and Fluent Validation... hint hint lol

  • @sushilb7994
    @sushilb7994 2 роки тому +1

    This is so far the best video on Global error handling in rest api . Excellent video and eagerly waiting for the next one!!!

  • @CRBarchager
    @CRBarchager 2 роки тому +4

    By far the best video on ErrorHandling I have ever seen. Very usefull and coincidentally what I'm about to implement in a project!

  • @TheScrowen
    @TheScrowen 2 роки тому +1

    Wow, today I started to build a new app just to learn some new things. I had some questions that I haven't found answers to for a while. You've already answered the some of them. Great guide!

  • @user-cp9np1sn3r
    @user-cp9np1sn3r Рік тому +1

    Found this series now and I must say they are so good! You manage to fit so much helpful content in such a short time, and has really opened my eyes for new areas in dotnet.
    Also, great to be able to follow your workflow (how to walk through other source code) and all the plugins used in vscode.

  • @unhandledexception1948
    @unhandledexception1948 Місяць тому

    These videos are so loaded with info, I have to slow them down to keep up

  • @mtsLeal
    @mtsLeal 5 місяців тому

    This playlist is incredible, I'm learning a lot of aspnet core features. Thank you so much for this!

  • @vivekverma30494
    @vivekverma30494 2 роки тому +2

    I love your pace. Thank you for all these detailed and direct to the point video. These videos are not for beginners but they can follow along and read about the methods and style of coding and patterns that you are following. Diving into the source code to give details of implementation is great. Really clear some of the things which happen magically.

  • @edwardnovikov4326
    @edwardnovikov4326 2 роки тому +2

    finally, thanks!
    I'm learning asp net and did good job until that point when i realized that every extend or change led to 2-3 hours of debugging. Project was 100% monolith and i didn't know what to do. Yes, I could write working apps, but they were always very messy ;(
    Keep going

  • @propro8040
    @propro8040 Рік тому +1

    Hey,
    Thanks for putting together this great video series on data engineering! I'm really enjoying it.
    Keep up the great work

  • @MilanJovanovicTech
    @MilanJovanovicTech 2 роки тому +3

    Interesting approach with the error endpoint. My personal favorite is using an exception-handling middleware. I also like to implement the IMiddleware interface for strong typing, it won't hurt.

    • @amantinband
      @amantinband  2 роки тому +2

      Yes, that's a safer approach. I wanted to avoid talking about adding it to the IoC container. Do you return ProblemDetails from your services or a custom error response?

    • @MilanJovanovicTech
      @MilanJovanovicTech 2 роки тому

      @@amantinband I return a ProblemDetails response, but with my own kind of format 🤔

    • @amantinband
      @amantinband  2 роки тому +3

      @@MilanJovanovicTech I see. For some reason many project define their own error model instead of using the common RFC specification. Perhaps it's not known enough yet

    • @MilanJovanovicTech
      @MilanJovanovicTech 2 роки тому +2

      @@amantinband Most of the APIs I've seen in the wild aren't even RESTful, so nothing surprises me 😁

    • @faixalnazir6593
      @faixalnazir6593 2 роки тому +1

      Yes, I like to handle exception handling by using middleware. But for custom error handling according to @Amichai error detail factory is better.

  • @batiku1
    @batiku1 10 місяців тому

    Great video!
    I'd like to note that you can actually inject a ProblemDetailsFactory either into a middleware or a filter attribute. So you can combine the benefit of using the ProblemDetailsFactory even with the 'middleware' or the 'filter' aproach.

  • @nalux
    @nalux 4 місяці тому +1

    I know this video has been out for a minute or two. I just want to make sure I understand the premises correctly here. The title is referring to "Global Error Handling", yet we are predominantly dealing with the aspects of an HTTP context. How is this global in any sense? I can understand the benefit and use case for this, I am merely curious about the scope for this, because Global is a rather large scope, and I don't see this error handling being able to capture something like a null ref exception in a part of the code that is not dealing with the http context.
    So, all in all, love the series and this video as well! Just getting somewhat confused on this specific terminology, perhaps it should be something like "Global API Error Response" or "HttpContext Error Response". Please tell me if I am totally going off my rails here :)
    And again, good series Amichai :)

  • @hpdev93
    @hpdev93 2 роки тому +2

    Loving this series, please continue, Thank you

  • @PeriMCS
    @PeriMCS 2 роки тому

    Probably one of the best instructional videos I have watched!

  • @Chtonik
    @Chtonik Рік тому

    Great ! Didn't know about the problem details rfc recommandation !

  • @ryanheitmann7591
    @ryanheitmann7591 2 роки тому

    Really enjoying the series so far, keep up the good work!

  • @danirdd92
    @danirdd92 2 роки тому +1

    קצת תוכן ישראלי איכותי עם מבטא זה תמיד טוב 😁

  • @DanielTames
    @DanielTames 2 роки тому +1

    Hey sensei!
    Are we gonna see unit testing? I'm really curious to see how we can manage unit testing with this kind of project, because in many videos you said that you change some code in order to test it easier in the future!
    Thank you very much for all the effort again, you are changing lifes with this types of videos.

  • @ammarahmed4140
    @ammarahmed4140 Рік тому

    thanks for sharing all this information.. really appreciate your efforts. it helps alot.. keep sharing good stuff!!

  • @joelmuskwe
    @joelmuskwe Рік тому +2

    Need help the DefaultProblemDetailsFactory now references ProblemDetailsContext and ProblemDetailsOptions that I can't seem to resolve in the BuberDinnerProblemDetailsFactory

    • @JesuMarquez
      @JesuMarquez Рік тому

      I just remove this and this work for me

  • @mylesdavies9476
    @mylesdavies9476 2 роки тому

    Series is awesome, really looking forward to seeing how this progresses 🙂

    • @amantinband
      @amantinband  2 роки тому

      Awesome to hear. Thanks, Myles!

  • @nivaldobrasil
    @nivaldobrasil Рік тому +1

    Thank you

  • @albenvi94
    @albenvi94 2 роки тому +1

    How can we dynamically pass the http status code to the /error endpoint?

  • @Parthibansekar87
    @Parthibansekar87 Рік тому

    Love this series! Very informative and reaffirming!

  • @kyreehenry9202
    @kyreehenry9202 2 роки тому

    To be honest, when i started watching the video, i didn't like the way you talked fast, but the deep explanation you gave made up for it

  • @IsaacOjeda
    @IsaacOjeda Рік тому

    Just seeing you how you use VS Code, I'm learning more

  • @glickyaron9490
    @glickyaron9490 Рік тому

    very detailed video. you have high standards. thanks!

  • @jamesevans6438
    @jamesevans6438 2 роки тому

    Completely agree with Daniel, putting into a separate video would be better, keeping the videos a bit cleaner

  • @drm1983
    @drm1983 2 роки тому

    Excelent series I'm enjoying it a lot. It would have been nice if Microsoft made that private method you modify in the custom factory implementation protected :)

  • @nucasspro1
    @nucasspro1 2 роки тому

    Really really helpful for a new guy, thank you so much

  • @99aabbccddeeff
    @99aabbccddeeff 10 місяців тому

    Awesome content, really informative and well explained! Thank a lot.

  • @noobyetdope4208
    @noobyetdope4208 2 роки тому

    Purely mind blowing... How did you even gain such command over c#
    any learning paths would be much appreciated
    Thanks for all the content you provide

    • @amantinband
      @amantinband  2 роки тому +1

      Haha you gotta remember these videos are edited and I wrote the same (or almost the same) code multiple times in the past

  • @serb1146
    @serb1146 Рік тому +1

    Hi Amichai, 1st, I wanna say you 1000 times thanks! for such a structured tutorial with schemes.
    I just wonder, why HandleExceptionAsync generated method is static? Thanks again.

    • @amantinband
      @amantinband  Рік тому

      Thanks Sergey! When methods aren’t dependent on non-static fields or properties it’s preferable to define them as static.

  • @thanhdungnguyen6816
    @thanhdungnguyen6816 11 місяців тому

    nice series, i love it. thank you so much

  • @arunghoshpushpakaran5133
    @arunghoshpushpakaran5133 2 роки тому

    It's a great series.
    I have a query: we often have requirements to log the API request and response when it gives unexpected results in the data access layer with its request and response.
    For example, when we are calling an API, if it returns an unsuccessful response, we want to log the request and the response along with the GUID passed in the request. Here in clean architecture, how can we use a common implementation for logging? We may need to log at different stages in a flow based on the business rules or exceptions.
    Stages:
    API-request and response logging (Middleware)
    Application-Logging based on the business case failure or unexpected failure.
    Infrastructure-when the API gives an unexpected response.

    • @arunghoshpushpakaran5133
      @arunghoshpushpakaran5133 2 роки тому

      I guess I've got the solution. Basically, I need to create an interface ILoggerService in the application and implement it in the infrastructure. And using this abstraction, I can use it in the API, application, and infrastructure projects.

  • @ahmetcanyldz7455
    @ahmetcanyldz7455 11 місяців тому

    Everything is super clear explanied and very helpful. But I have one question. Why don't you use Visual Studio?

  • @nec1211986
    @nec1211986 Рік тому +2

    subed, imaging access to this kind of knowledge for free

  • @geepy5708
    @geepy5708 Місяць тому

    Wow. Is it possible to remove even the traceID, type from the default problem details factory?

  • @pilotboba
    @pilotboba 2 роки тому +4

    Is user already registered really an "exception"? Sounds like using exceptions for business logic anti-pattern. Wouldn't some type of Result class or tuple be better so you are avoiding exceptions?
    (yes I know it is sort of orthogonal to the actual method of handling exceptions).

    • @amantinband
      @amantinband  2 роки тому +7

      The next video will be all about replacing exceptions for flow control with a monad approach. I think you’ll like it 😉

  • @mohammedelsuissey1745
    @mohammedelsuissey1745 2 роки тому

    Thanks bro, amazing content as always.

  • @alfonsdeda8912
    @alfonsdeda8912 7 місяців тому

    Hi, but in the caller, for example blazor, how should i handle problem details response, with a new exception?

  • @LoZioIAR
    @LoZioIAR 2 роки тому

    Thanks you! Very good series!

  • @TrueSportsHQ
    @TrueSportsHQ 2 роки тому

    Keep it coming, thank you!

  • @vincentbui8380
    @vincentbui8380 2 роки тому

    Good video, for some reason the ProblemDetailsFactory toss up an error about not having the CreateValidationProblemDetails function in its class.

  • @ferci2865
    @ferci2865 3 місяці тому

    I want to ask which extension suggested a bunch of code to him? Thanks.

  • @CursedFire10
    @CursedFire10 Рік тому

    So which one use?? which one provide an best capture when a need use a capture logger?

  • @skraptzz7273
    @skraptzz7273 8 місяців тому

    Can you explain what the TraceId is for? And how do I use it? :)

  • @al-doori2392
    @al-doori2392 2 роки тому

    Thanks god I found your channel thank you so much

  • @ibrahim-SO
    @ibrahim-SO Рік тому

    How did you open that mini search tool to open VS Code? is that built-in windows feature?

  • @atul121984
    @atul121984 2 роки тому

    Excellent Series.

  • @qniken8770
    @qniken8770 2 роки тому +1

    I love your videos. Keep going :)

    • @amantinband
      @amantinband  2 роки тому

      Awesome to hear. Thanks, Qniken 🤙

  • @DanielLaubinger
    @DanielLaubinger 2 роки тому +3

    Hey, love this series! Which tool are you using 16:00 to open VS Code?

    • @meetingattender8132
      @meetingattender8132 2 роки тому +2

      PowerToys (which has bunch of other useful tools that other OSes have built-in, this particular one is called PowerToys Run, Alt + Space, like Cmd + Space on MacOS)

    • @amantinband
      @amantinband  2 роки тому +2

      Yup, PowerToys. Has a few really awesome features 🤙

  • @zeeshanasghar3751
    @zeeshanasghar3751 Рік тому

    how to get traceId if using exception handling middleware

  • @microtech2448
    @microtech2448 Рік тому

    Nice video. More curious about whether you have any plugin installed which gives detailed code intelli and colorful breadcrumbs in the terminal?

  • @Lukex29
    @Lukex29 Рік тому

    How did it suggest that all that code? Can i get that enabled in visual studio 2022?

  • @raphaeldevmtb
    @raphaeldevmtb Рік тому

    Thanks!

  • @user-db6sq3ke7q
    @user-db6sq3ke7q Рік тому

    awesome course, thanks a lot

  • @abhishekbagchi6052
    @abhishekbagchi6052 2 роки тому

    Great video as always

  • @aliensoul7600
    @aliensoul7600 11 місяців тому

    @1:14 sir could you please tell me what application use to create this beautiful project presentation flow. Thank you 🤍🙏🏻

  • @JuanCamba81
    @JuanCamba81 Рік тому

    02:30 how did you do to autocomple ErrorHandlingMiddelware class?

  • @derDooFi
    @derDooFi 3 місяці тому

    when i saw the blue status bar with the green button in the lower left corner, for a second i thought i was looking at Windows XP

  • @tiagosutter8821
    @tiagosutter8821 Рік тому

    Thanks for the awesome content!
    Is adding "customProperty" really relevant using the custom problem details factory? Shouldn't I be having different extensions to the problem details depending on the error or endpoint called?

  • @AdrienDubois-cx7ci
    @AdrienDubois-cx7ci Рік тому

    I make the UseExceptionHandler Middlewae + the Error endpoint etc.. But when I start application and test the endpoint with an error, Visual Studio throws me a "Non handled exception by user's window " and stop the flow of the request. I really don't get it why. I saw your others videos and all is as same as you.
    If you may have any idea, you'll be the boss ( more than you already are :D )

  • @user-rp9iis1en6h
    @user-rp9iis1en6h 2 роки тому

    Thanks. How to implement audit in .net core?

  • @meetingattender8132
    @meetingattender8132 2 роки тому +1

    We are using Chillicream's Hotchocolate GraphQL with .NET 6 (with schema stitching with & redis cache in Azure for hot reload). We decided to use layout our downstream services (microservices) using your project layout in your series. Do you think one day you can make a video about how to use GraphQL with Clean Arch & DDD, specifically using Hotchocolate? Thank you

    • @amantinband
      @amantinband  2 роки тому +1

      I'll add it to my backlog. Perhaps at the end of the series I'll look into it

  • @AbdusSalamAzad
    @AbdusSalamAzad 2 роки тому

    What if I want to throw the exception from .NET core via middleware, action filter or anything else and want to receive or show that error in Angular 404 or 500 page with the error message?

  • @oui_chapeau
    @oui_chapeau 2 роки тому

    in what way is the "error endpoint/custom problem details factory" strategy better than using a middleware?

  • @krccmsitp2884
    @krccmsitp2884 Рік тому

    Great insight!

  • @atilla8773
    @atilla8773 2 роки тому

    Great stuff.. Many thanks.. When is the next one?

  • @narekhovhannisyan6362
    @narekhovhannisyan6362 Рік тому

    Good video thanks

  • @2ndaryexplosion674
    @2ndaryexplosion674 2 роки тому

    how about docker support, if for example you've got 2 or more adapters in DDD?

  • @ShikiWeiss
    @ShikiWeiss Рік тому

    סדרה מדהימה! תודה על ההשקעה🙏

  • @S3Kglitches
    @S3Kglitches 2 роки тому

    How does returning a custom object upon error work with expecting exact DTO from the endpoint? Doesn't it break the logic?

  • @meirkr
    @meirkr 2 роки тому

    Great video! Tx!
    Can the "/error" endpoint be inaccessible to clients and be accessible only in-proc?

  • @markohrncic2928
    @markohrncic2928 Рік тому

    First of all, fantastic video!
    Is there any specific reason why you are using HttpStatusCode enum that you are then casting to integer? As opposed to the StatusCodes which are integers already? Just curious :)

  • @AI-ForFun
    @AI-ForFun Рік тому

    What extension do you use to get that auto completion/suggestion once you create the file and even before you start typing?

  • @YvesRomeiro-ct9tm
    @YvesRomeiro-ct9tm Рік тому

    Amazing Content !!

  • @jackdaniel4936
    @jackdaniel4936 2 роки тому

    Hello sir, thanks for great explanation. I am just wondering let's say we have global exception handling middleware, and can we say that our API never crash? I mean any error we have the the code will hit the catch in our middleware and it will return an message to clients in worst scenario right? So in this case can we say that an API which has global exception handling middleware never crashes? Thank you very much again for great videos 💯

  • @bluewhale.068
    @bluewhale.068 Рік тому

    15:01
    Failed to load API definition.
    Errors
    Hide :(((
    i think your code missing httpget in errorscontroller

  • @peterposnag
    @peterposnag 2 роки тому

    Can I use UseExceptionHandler for bad request status code?

  • @path_selector
    @path_selector 11 місяців тому

    eeeyesss!!!

  • @DaminGamerMC
    @DaminGamerMC 2 роки тому

    which software are you using for the red rectangles and arrows that appear on screen?

  • @tesszheng8132
    @tesszheng8132 2 роки тому

    Hi Amichai, I am wondering how this code generated automatically when you just type "ErrorHandlingMiddleware", do I need to install any extension to achieve this?

  • @JorgeFPCardoso1
    @JorgeFPCardoso1 2 роки тому

    Really enjoying this series. Can you please tell me what software you use to make the infographic layouts that you show on your videos?

    • @amantinband
      @amantinband  2 роки тому

      I use Figma for all the design stuff & ZoomIt to draw on the screen

  • @vagnerpadilha3485
    @vagnerpadilha3485 2 роки тому

    Hi Amichai, congratulations for this series you are amazing.
    Can you explain to me? if you have `FormOptions` set with size limit, how can you catch in Global Error Handling if the payload is too large and map the error to an problem detail with status code 413. Would be useful when uploading images.
    services.Configure(s =>
    {
    options.ValueLengthLimit = 1000;
    options.MultipartBodyLengthLimit = 1000;
    options.MemoryBufferThreshold = 1000;
    });

  • @varadashvili
    @varadashvili Рік тому

    Hi, Thanks for informative video. Is it possible to use this approach instead of CustomProblemDetailsFactory ?
    [Route("/error")]
    public IActionResult Error()
    {
    var exceptionHandlerFeature = HttpContext.Features.Get();
    var exception = exceptionHandlerFeature?.Error;
    var path = exceptionHandlerFeature?.Path;
    var problemResult = Problem(title: exception.Message, statusCode: 400, instance: path);
    var problemDetails = problemResult.Value as ProblemDetails;
    problemDetails.Extensions.Add("customProperty", "customValue");
    return problemResult;
    }

  • @mouradaissani8957
    @mouradaissani8957 2 роки тому

    Another great video, well explained, i like your videos, keep it up plz
    Demande: can you please show the keystrokes on the screen? oh man the way you are using VS code is so impressive, i would like to learn all those keystockes

    • @amantinband
      @amantinband  2 роки тому +5

      Thanks, Mourad! I tried it with a draft video and I was worried it made the screen too cluttered. Especially with the vim extension which I use to navigate around the screen. If you are reading the comments and you would also like this, give this comment a like and I'll give it a try if enough of you are interested 🤙

    • @danielkiesel4440
      @danielkiesel4440 2 роки тому +4

      Personally, I would prefer a dedicated video showcasing this (+maybe additional) extensions and how you use them so efficiently. In that video, showing all keystrokes would be amazing. In general, though, I think it will distract too much from the content which is very well paced already.
      Keep it up, you are already amongst my favorite coding youtube channels after 4 episodes. 👍

  • @MahmoudMouradSidky
    @MahmoudMouradSidky Рік тому

    Super video, BTW what is the extension that auto complete your code (the whole class) for you?

  • @luckies6945
    @luckies6945 Рік тому

    Wow, good Stuff!

  • @Hosseinabdn
    @Hosseinabdn 2 роки тому

    Hi. Thank you for this great video. In this video, something caught my attention. When you gone to definition of ControllerBase,
    its content was visible. But for me only the summary is visible and the implementation is not available. How can you do it?

    • @amantinband
      @amantinband  2 роки тому

      The suggestions are coming from the GitHub Co-Pilot extension. It now publicly available and costs 10$ a month

  • @ademonurcelik
    @ademonurcelik Рік тому

    I'm getting 404 instead of 500. Using .NET 7.0.

  • @yashwanthd1998
    @yashwanthd1998 2 роки тому

    Whats the font name???

  • @TheElgaard
    @TheElgaard Рік тому

    You just got a supporter on patreon, great video! However, I seem to get an error in swagger when I'm implementing the third solution. Swagger starts and I get a an 500 where it says: Failed to load API definition. Do you happen to know why?

    • @xtr3me0wnz
      @xtr3me0wnz Рік тому

      You need to mark the controller as : [ApiExplorerSettings(IgnoreApi = true)]
      I had the same problem

  • @andreaskroll
    @andreaskroll 2 роки тому

    What are you using to show the screenshot contents?

  • @muralikrishnachowdarypolin5601
    @muralikrishnachowdarypolin5601 2 роки тому

    Hi can I get Buber dinner app source code if any chance

    • @amantinband
      @amantinband  2 роки тому

      Hi Muralikrishnachowdary, the source code is available for patrons, but you can follow the series all along by following the videos

    • @muralikrishnachowdarypolin5601
      @muralikrishnachowdarypolin5601 2 роки тому

      @@amantinband i join as patron i can get total dinner app code

  • @joe-sydney-au
    @joe-sydney-au Рік тому

    It It was a lot easier with the previous .NET v4.x; We could write something like the following, out-of-the box :
    1) return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
    2) throw new HttpResponseException( Request.CreateErrorResponse( HttpStatusCode.NotFound, message) );
    Any client library (e.g. axios, fetch) could easily capture the status-code, and custom message thrown by the web-api without much effort on the Dev's part. Does anyone seriously think this is progress?