Skip to content

Commit

Permalink
Added undefined check to ping
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamish-taylor committed May 31, 2024
1 parent 05ec7b7 commit caf1df5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/raygun.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,15 @@
};

function ping() {
if(metadata.ping.failedPings > 10) {
if(metadata.ping.failedPings > 2) {
clearInterval(metadata.ping.pingIntervalId);
}

if(!Raygun.Options || !Raygun.Options._raygunApiKey || !Raygun.Options._raygunApiUrl){
metadata.ping.failedPings++;
return;
}

var url = Raygun.Options._raygunApiUrl + "/ping?apiKey=" + encodeURIComponent(Raygun.Options._raygunApiKey);
var data = {
crashReportingEnabled: crashReportingEnabled ? true : false,
Expand All @@ -245,18 +250,17 @@
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(function(response) {
if (response.ok) {
metadata.ping.failedPings = 0;
} else {
// Request failed
metadata.ping.failedPings++;
}
})
.catch(function() {
if (response.ok) {
metadata.ping.failedPings = 0;
} else {
// Request failed
metadata.ping.failedPings++;
}
}).catch(function() {
metadata.ping.failedPings++;
});
}
Expand Down

0 comments on commit caf1df5

Please sign in to comment.