Fixing how chained middleware errors are handled