Reconfigure middleware to catch errors correctly.