From the course: Building Web APIs with ASP.NET Core 8
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Handling errors
From the course: Building Web APIs with ASP.NET Core 8
Handling errors
- [Instructor] We just got an HTTP 204 status code, I just looked it up in the specification, it means no content. And that absolutely makes sense, we were asking for the item with the ID 42, there is no such item, so there's nothing to server could have returned. But remember that in the REST principle, the HTTP status codes are taken into account, and there is a status code for we can't find anything, that's HTTP 404 not found. So actually we should return that in those cases. And this is how error handling works in general. Here's our implementation so far. So we have our action method, it's finding a product and then it does return okay of product, which means HTTP status code 200 converted or serialized into JSON will be returned. But what if there is no such product? We would like to return HTTP 404 and since the status code that's called okay, 200, is represented by the okay method, you guessed right there is also a not found method and return not found essentially returns HTTP…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Controllers and actions7m 50s
-
(Locked)
Routing basics6m 14s
-
(Locked)
Creating a data model5m 54s
-
(Locked)
Using entity framework core7m 28s
-
(Locked)
Returning a list of items4m 4s
-
(Locked)
Using ActionResult2m 44s
-
(Locked)
Returning an item4m 29s
-
(Locked)
Handling errors3m 5s
-
(Locked)
Making the API asynchronous2m 51s
-
(Locked)
Working with minimal APIs5m 22s
-
(Locked)
Challenge: Searching items31s
-
(Locked)
Solution: Searching items3m 1s
-
(Locked)
-
-