Hi @DineshPrasanth
caution: in your example, you are fetching the whole website again which makes little sense and causes unnecessary network traffic and slows down your page.
Can you identify the error page somehow, meaning through its document title containing "404" or "error", or any other dom elements on the page which indicate an error?
That way you could create a data element that is just returning whether this information was found.
In your case of the "404 checker" it would rather look something like this
// use what ever you can use to detect an error page
return document.title.includes("404") || document.title.includes("error");
If you cannot identify error pages, ask your developers to make it identifiable.
Hope that helps
Cheers from Switzerland!