From 785ef6493e36f81fb0536dfedc9eb9774abd9d03 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Mon, 13 Mar 2023 09:57:53 +0000 Subject: [PATCH] apply readystatechange logic to sessions --- packages/delivery-xml-http-request/delivery.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/delivery-xml-http-request/delivery.js b/packages/delivery-xml-http-request/delivery.js index 61886ec2ce..6992959ba8 100644 --- a/packages/delivery-xml-http-request/delivery.js +++ b/packages/delivery-xml-http-request/delivery.js @@ -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)