fix middleware in case of exceptiond. pep8