Middleware
Learn why we need middleware.
We'll cover the following
Importance of middleware
In one of the previous lessons, we added several resolution and error-handling functions. The error-handling functions enable the system to give users feedback about errors that bubble up from the underlying database. These problems range from internal schema validation problems like missing and badly formatted arguments to database constraint violations. If we add more resolvers to power the ordering system, we just copy and paste the same code into that resolver. Clearly, this isn’t the approach we would want to take as the API expands. If we want to let Absinthe know how to handle changeset errors, we’re going to need to build a middleware module to do so. Let’s start by ripping the error transformation logic out of our resolver modules and putting it inside a new module that serves as the base of our middleware.
Get hands-on with 1400+ tech skills courses.