Use ensure to simplify middlewares

Instead of rescuing exceptions, running the respective clean up code and
re-raising exceptions, simply use an ensure statement instead.