Learn about using the HttpResponseException to wrap an exception and force Web API to return a specific response.
- [Instructor] There are four different ways…that we can handle exceptions in our Web API application.…The first of those ways happens to be…right in your controller's action method…where the exception is thrown.…You may remember talking about the HTTP response exception…earlier in this course,…but let's take a look back at it right now.…Here we're looking at the search method…that we created for the tours controller.…If you recall,…we used an HTTP response exception…to return a specific HTTP response code…when the request was invalid.…
Specifically, we were throwing an exception…if the min price was larger than the max price.…There was no underlying exception…that was bubbling up to our controller in this case.…Instead, we actually created the exception…to force that 400 bad request response that we wanted.…Another time, though,…that you might want to use the HTTP response exception…would be to wrap an underlying exception…that we're catching in our controller.…For example, what if Entity Framework threw an exception…
AuthorJonathan "J." Tower
- Convention-based routing
- Binding your code to an HTTP request
- Validating models
- Using attributes to route requests
- Customizing attribute routes
- Data serialization and model binding
- Error handling
- Using exception filters and exception loggers
- API documentation and testing
- Securing your API
Skill Level Beginner
ASP.NET MVC: HTTP Request Life Cyclewith Janan Siam2h 15m Advanced
1. Controllers and Actions
3. Data Serialization and Model Binding
4. Error Handling
5. API Documentation and Testing
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.