This is possible, but only if a page isn't cached yet. If a page with errors is already cached, there is no way to check anything, because a cached page is only plain text and there is no more PHP interpretor. You must find a way to add this code in PrestaShop, but it must be last header that is...