Wrapper function for middleware to handle errors consistently
The middleware function
A wrapped middleware function that handles errors
Wrapper function for middleware to handle errors consistently