Moved the middleware callback out of a try catch block.