Wrap middleware in try/except.