Added error passing in middleware