Skip to content

Commit

Permalink
apply readystatechange logic to sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerbenw committed Mar 13, 2023
1 parent b2f804a commit 785ef64
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/delivery-xml-http-request/delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ module.exports = (client, win = window) => ({
try {
const url = client._config.endpoints.sessions
const req = new win.XMLHttpRequest()

req.onreadystatechange = function () {
if (req.readyState === win.XMLHttpRequest.DONE) cb(null)
if (req.readyState === win.XMLHttpRequest.DONE) {
const status = req.status
if (status === 0 || status >= 400) {
const err = new Error(`Request failed with status ${status}`)
client._logger.error('Session failed to send…', err)
cb(err)
} else {
cb(null)
}
}
}

req.open('POST', url)
req.setRequestHeader('Content-Type', 'application/json')
req.setRequestHeader('Bugsnag-Api-Key', client._config.apiKey)
Expand Down

0 comments on commit 785ef64

Please sign in to comment.