Skip to content

Instantly share code, notes, and snippets.

@PoOwAa
Created January 8, 2019 13:23
Show Gist options
  • Save PoOwAa/85c7251632d26ce9379103a93cae1916 to your computer and use it in GitHub Desktop.
Save PoOwAa/85c7251632d26ce9379103a93cae1916 to your computer and use it in GitHub Desktop.
const qs = "http://notworkingurl.com";
fetch(qs)
.then(response => {
return response.json();
})
.then(data => {
// Working code
console.log(data);
})
.catch(error => {
console.error("######## I GOT ONE ########");
console.error(error);
const myLoggerUrl = "http://example.com/";
fetch(myLoggerUrl, {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
redirect: "follow",
referrer: "no-referrer",
body: JSON.stringify(error)
})
.then(response => {
return response.json();
})
.then(data => {
console.log("Log sent successfully!");
})
.catch(error => {
console.error("######## I GOT ONE ########");
console.error("Logger server is not available");
console.error(error);
// Esetleg itt localStorage-be helyezni vagy bármi
});
});
<html>
<head>
<script src="./catchError.js"></script>
<title>Error küldő izébizé</title>
</head>
<body>
Error küldő izébizé
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment