From 60df34b185a67f4e92c8dc32b96d04255c0fb384 Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Sat, 22 Jul 2017 13:56:26 +0200 Subject: [PATCH 1/3] add column number and error_object and make requests asynchronous --- .../templates/django_js_error_hook/utils.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/django_js_error_hook/templates/django_js_error_hook/utils.js b/django_js_error_hook/templates/django_js_error_hook/utils.js index 783b43b..5c536bc 100644 --- a/django_js_error_hook/templates/django_js_error_hook/utils.js +++ b/django_js_error_hook/templates/django_js_error_hook/utils.js @@ -10,17 +10,9 @@ return null; } function logError(details) { - var xhr; - try { - xhr = new ActiveXObject('Msxml2.XMLHTTP'); - } catch (e1) { - try { - xhr = new ActiveXObject('Microsoft.XMLHTTP'); - } catch (e2) { - xhr = new XMLHttpRequest(); - } - } - xhr.open("POST", "{% url 'js-error-handler' %}", false); + var xhr = new XMLHttpRequest(); + + xhr.open("POST", "{% url 'js-error-handler' %}", true); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); var cookie = getCookie('csrftoken'); if (cookie) { @@ -36,7 +28,14 @@ xhr.send(query.join('&')); } - window.onerror = function(error_msg, url, line_number) { - logError(url + ':' + line_number + ': ' + error_msg); + window.onerror = function(msg, url, line_number, column_number, error_obj) { + var log_message = url + ': ' + line_number + ': ' + msg; + if (column_number) { + log_message += ", " + column_number; + } + if (error_obj) { + log_message += ", " + JSON.stringify(error); + } + logError(log_message); }; })(); From 0d90b786c17d04b343db3479a4fc125d80126e60 Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Sat, 22 Jul 2017 14:21:15 +0200 Subject: [PATCH 2/3] typo --- django_js_error_hook/templates/django_js_error_hook/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_js_error_hook/templates/django_js_error_hook/utils.js b/django_js_error_hook/templates/django_js_error_hook/utils.js index 5c536bc..fab83bc 100644 --- a/django_js_error_hook/templates/django_js_error_hook/utils.js +++ b/django_js_error_hook/templates/django_js_error_hook/utils.js @@ -34,7 +34,7 @@ log_message += ", " + column_number; } if (error_obj) { - log_message += ", " + JSON.stringify(error); + log_message += ", " + JSON.stringify(error_obj); } logError(log_message); }; From 0a282b11ee1052696f87885c220720c93b61336a Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Sat, 22 Jul 2017 14:29:27 +0200 Subject: [PATCH 3/3] fix for stack --- django_js_error_hook/templates/django_js_error_hook/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_js_error_hook/templates/django_js_error_hook/utils.js b/django_js_error_hook/templates/django_js_error_hook/utils.js index fab83bc..ec5b6bf 100644 --- a/django_js_error_hook/templates/django_js_error_hook/utils.js +++ b/django_js_error_hook/templates/django_js_error_hook/utils.js @@ -33,8 +33,8 @@ if (column_number) { log_message += ", " + column_number; } - if (error_obj) { - log_message += ", " + JSON.stringify(error_obj); + if (error_obj && error_obj.stack) { + log_message += ", " + error_obj.stack; } logError(log_message); };