Added custom error middleware and mongodb connection retry