Debugging the Rust application
In the previous section, we learned about writing functional tests, but sometimes, the test fails. We want to know why the test failed. There are two possible places where the error might occur. One is in the user creation process, and the other is in finding users after creating the user.
One way to debug is by logging where the error might occur. If we log all the possible errors in the user creation process (for example, in src/routes/user.rs
in the create_user()
function), we will find out that the authenticity token verification sometimes produces an error. An example of logging the error is as follows:
csrf_token
.verify(&new_user.authenticity_token)
.map_err(|err| {
log::error!("Verify authenticity_token error: {}",
err);
...