Skip to content

Commit 7cf4cd7

Browse files
committed
throttle js error reports to 1 per 5 secs.
and ignore more scribd errors fixes #39274 Change-Id: Ie1ebcd4dd9e004f65d8fee68d97b2ffb377a5d22 Reviewed-on: https://gerrit.instructure.com/5820 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Jon Jensen <jon@instructure.com>
1 parent c7f1139 commit 7cf4cd7

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

public/javascripts/ajax_errors.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919
var iTest;
2020
INST.errorURL = '/record_js_error';
2121
INST.errorCount = 0;
22+
INST.errorLastHandledTimes = {};
2223
INST.log_error = function(params) {
2324
params = params || {};
25+
var timestamp = +new Date();
26+
// log errors with the same message once every 5 seconds at most.
27+
// (so we don't fill the DOM with logging gifs)
28+
if (INST.errorLastHandledTimes[params.message] > timestamp - 5000) return;
29+
INST.errorLastHandledTimes[params.message] = timestamp;
2430
var username = "";
2531
try {
2632
username = $ && $.fn && $.fn.text && $("#identity .user_name").text();
@@ -48,7 +54,8 @@ INST.log_error = function(params) {
4854
document.body.appendChild(img);
4955
}
5056
window.onerror = function (msg, url, line) {
51-
var ignoredErrors = ["webkitSafeEl"];
57+
// these are errors that the actionScript in scrbd creates.
58+
var ignoredErrors = ["webkitSafeEl", "NPMethod called on non-NPObject wrapped JSObject!"];
5259
for(var idx in ignoredErrors) {
5360
if(ignoredErrors[idx] && msg && msg.match && msg.match(ignoredErrors[idx])) {
5461
return true;
@@ -164,4 +171,4 @@ $(document).ready(function() {
164171
});
165172

166173
});
167-
});
174+
});

spec/selenium/error_reports_sel.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/common')
2+
3+
describe "error reporting" do
4+
it_should_behave_like "in-process server selenium tests"
5+
it "should log the same error at most 1 time per 5 seconds" do
6+
get('/logout')
7+
4.times do
8+
driver.execute_script("window.onerror('Throwing a test error', ''+document.location, 12)")
9+
end
10+
driver.execute_script("return $('body > img[src^=\"'+ INST.errorURL +'\"]').length").should == 1
11+
end
12+
end

0 commit comments

Comments
 (0)