5 Handling errors

 

This chapter covers

  • Setting up the project structure
  • Basics of error handling in Rust and Actix Web
  • Defining a custom error handler
  • Error handling for retrieving all courses
  • Error handling for retrieving course details
  • Error handling for posting a new course
  • Summary

In the previous chapter, we wrote the code to post and retrieve courses through an API. But what we demonstrated and tested were the happy path scenarios. In the real world however, many types of failures can occur. The database server may be unavailable, the tutor id provided in request may be invalid, there may be a web server error, and so on. It is important that our web service is able to detect the errors , handle them gracefully and send a meaningful error message back to the user or client sending the API request. This is done through error handling, which is the focus of this chapter. Error handling is important not just for stability of our web service, but also to provide a good user experience.

Figure 5.1. Unifying error handling in Rust
600

5.1 Setting up the project structure

5.2 Basics of error handling in Rust and Actix Web

5.3 Defining a custom error handler

5.4 Error handling for retrieving all courses

5.5 Error handling for retrieving course details

5.6 Error handling for posting a new course

5.7 Summary

sitemap