-
Book Overview & Buying
-
Table Of Contents
Rust Web Programming - Third Edition
By :
We are at the final hurdle of this chapter, where we want to get rid of the match statement in our API functions for our server. The match statement is a result of us handling an error. As our server grows, we would have to repeat the clunky handling of errors again and again, and there is a risk that we could mishandle the error. To prevent having to manually handle the errors for every API endpoint, we can bake the HTTP responses into our error handling. To do this, we can create an error type that can construct an HTTP response, so we can exploit the ? operator in our web API function, and the server will simply respond with an HTTP response. However, this means that all our Cargo workspaces need to share the same custom error types. This is where a glue module will come in. A glue module is a crate that all other workspaces install. With this glue module, all Cargo workspaces can seamlessly pass the same error type between each other.
Glue...