Skip to content

Commit

Permalink
Legger til try/catch, og logger error til sentry.
Browse files Browse the repository at this point in the history
  • Loading branch information
otenav committed Apr 22, 2022
1 parent eb7a003 commit 053112e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/hooks/useRobotsNoIndexMetaTag.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { useEffect } from "react";
import { captureMessage } from "@sentry/browser";

function removeRobotsMetaTag() {
let metaRobots = document.head.querySelector("meta[name=robots]");
if (metaRobots) {
document.head.removeChild(metaRobots);
let metaRobots;
try {
metaRobots = document.head.querySelector("meta[name=robots]");
if (metaRobots) {
document.head.removeChild(metaRobots);
}
} catch (e) {
captureMessage("Error in removeRobotsMetaTag. metaRobots is " + metaRobots);
}
}

function addRobotsNoIndexMetaTag() {
const content = "noindex";
let metaRobots = document.head.querySelector("meta[name=robots]");
try {
const content = "noindex";
let metaRobots = document.head.querySelector("meta[name=robots]");

if (!metaRobots) {
metaRobots = document.createElement("meta");
metaRobots.setAttribute("name", "robots");
metaRobots.setAttribute("content", content);
document.head.appendChild(metaRobots);
} else {
metaRobots.setAttribute("content", content);
if (!metaRobots) {
metaRobots = document.createElement("meta");
metaRobots.setAttribute("name", "robots");
metaRobots.setAttribute("content", content);
document.head.appendChild(metaRobots);
} else {
metaRobots.setAttribute("content", content);
}
} catch (e) {
captureMessage("Error in addRobotsNoIndexMetaTag");
}
}

Expand Down
2 changes: 1 addition & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
</div>
{{> components/footer}}
</div>
<script type="application/javascript" src="/stillinger/js/sok.js?random=1sasdasdadfdasdsdsad11"></script>
<script type="application/javascript" src="/stillinger/js/sok.js?random=1sasdasdadfdasasddsdsad11"></script>
</body>
</html>

0 comments on commit 053112e

Please sign in to comment.