From a1c0a5cf215236ef46869e5f1bda4d307bd3ff3b Mon Sep 17 00:00:00 2001 From: Andrew Weiss Date: Mon, 14 Aug 2017 16:08:17 +0200 Subject: [PATCH 1/2] update the level when we find out the status --- src/browser/telemetry.js | 6 ++++-- src/telemetry.js | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/browser/telemetry.js b/src/browser/telemetry.js index 0faad2a0e..baf8c37ae 100644 --- a/src/browser/telemetry.js +++ b/src/browser/telemetry.js @@ -105,7 +105,7 @@ Instrumenter.prototype.instrumentNetwork = function() { if (xhr.__rollbar_xhr && (xhr.readyState === 1 || xhr.readyState === 4)) { if (xhr.__rollbar_xhr.status_code === null) { xhr.__rollbar_xhr.status_code = 0; - self.telemeter.captureNetwork(xhr.__rollbar_xhr, 'xhr'); + xhr.__rollbar_event = self.telemeter.captureNetwork(xhr.__rollbar_xhr, 'xhr'); } if (xhr.readyState === 1) { xhr.__rollbar_xhr.start_time_ms = _.now(); @@ -114,7 +114,9 @@ Instrumenter.prototype.instrumentNetwork = function() { } try { var code = xhr.status; - xhr.__rollbar_xhr.status_code = code === 1223 ? 204 : code; + code = code === 1223 ? 204 : code; + xhr.__rollbar_xhr.status_code = code; + xhr.__rollbar_event.level = self.telemeter.levelFromStatus(code); } catch (e) { /* ignore possible exception from xhr.status */ } diff --git a/src/telemetry.js b/src/telemetry.js index ac729634f..0ce4bd54d 100644 --- a/src/telemetry.js +++ b/src/telemetry.js @@ -51,10 +51,20 @@ Telemeter.prototype.captureLog = function(message, level, rollbarUUID, timestamp Telemeter.prototype.captureNetwork = function(metadata, subtype, rollbarUUID) { subtype = subtype || 'xhr'; metadata.subtype = metadata.subtype || subtype; - var level = levelFromStatus(metadata.status_code); + var level = this.levelFromStatus(metadata.status_code); return this.capture('network', metadata, level, rollbarUUID); }; +Telemeter.prototype.levelFromStatus(statusCode) { + if (statusCode >= 200 && statusCode < 400) { + return 'info'; + } + if (statusCode === 0 || statusCode >= 400) { + return 'error'; + } + return 'info'; +}; + Telemeter.prototype.captureDom = function(subtype, element, value, checked, rollbarUUID) { var metadata = { subtype: subtype, @@ -123,14 +133,4 @@ function getLevel(type, level) { return defaultLevel[type] || 'info'; } -function levelFromStatus(statusCode) { - if (statusCode >= 200 && statusCode < 400) { - return 'info'; - } - if (statusCode === 0 || statusCode >= 400) { - return 'error'; - } - return 'info'; -} - module.exports = Telemeter; From bbdc138e49aa310b6dc3392ca56ab82962d87098 Mon Sep 17 00:00:00 2001 From: Andrew Weiss Date: Mon, 14 Aug 2017 20:27:37 +0200 Subject: [PATCH 2/2] fix typo --- src/telemetry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/telemetry.js b/src/telemetry.js index 0ce4bd54d..f33800dd4 100644 --- a/src/telemetry.js +++ b/src/telemetry.js @@ -55,7 +55,7 @@ Telemeter.prototype.captureNetwork = function(metadata, subtype, rollbarUUID) { return this.capture('network', metadata, level, rollbarUUID); }; -Telemeter.prototype.levelFromStatus(statusCode) { +Telemeter.prototype.levelFromStatus = function(statusCode) { if (statusCode >= 200 && statusCode < 400) { return 'info'; }