error handling - should run for an empty array or connection error