catch error when connecting to mongodb