Handling errors in API endpoints
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. 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 a 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. Before we create this glue module, we must appreciate what is happening to our whole system. Our nanoservice is just sitting there. If we put the glue module next to our nanoservice, then it can get confusing as to what is what. To reduce the risk of confusion, we need to shift our nanoservice into its own directory called nanoservices
. The nanoservices...