check element exists first
Merge pull request #6859 from guardian/fix-sentry-2736

Fix Sentry #2736