Updated query to only fetch last 1000 errors. If it attempts to fetch too many, it will crash.