How it works...
actix-web uses an error trait to convert Rust errors into HttpResponses. This trait is automatically implemented for a range of default errors but only by responding with the default Internal Server Error message.
In step 1 and step 2, we are setting up custom errors so that we can return messages that are relevant to what the user is currently doing (or trying to do). As with other errors (see Chapter 5, Handling Errors and Other Results), we are using enums to provide an umbrella to match error variations to. Each of the variants is augmented with an attribute that provides a corresponding error message with a format string—an ability provided by the failure crate (https://crates.io/crates/failure). The message here is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access