5 Handling errors

This chapter covers

  • Setting up the project structure
  • Handling errors in Rust and Actix Web
  • Defining a custom error handler
  • Error handling for the three APIs

In the previous chapter, we wrote the code to post and retrieve courses through APIs, 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 the request may be invalid, there may be a web server error, and so on. It is important that our web service be able to detect 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 ...

Get Rust Servers, Services, and Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.