Handle errors in forEach