Reordered the middleware to correctly use the logger and errohandler

#183