Skip to content

Commit 5cf95c0

Browse files
committed
Prevent error flooding
1 parent 7f5dee8 commit 5cf95c0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/browser/extension/utils/notifyErrors.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
let handleError;
2+
let lastTime = 0;
3+
4+
function createExpBackoffTimer(step) {
5+
let count = 1;
6+
return function(reset) {
7+
// Reset call
8+
if (reset) {
9+
count = 1;
10+
return 0;
11+
}
12+
// Calculate next timeout
13+
let timeout = Math.pow(2, count - 1);
14+
count += 1;
15+
return timeout * step;
16+
};
17+
}
18+
19+
const nextErrorTimeout = createExpBackoffTimer(1000);
220

321
function postError(message) {
422
if (handleError && !handleError()) return;
@@ -10,7 +28,11 @@ function postError(message) {
1028
}
1129

1230
function catchErrors(e) {
13-
if (window.devToolsOptions && !window.devToolsOptions.notifyErrors) return;
31+
if (
32+
window.devToolsOptions && !window.devToolsOptions.notifyErrors
33+
|| e.timeStamp - lastTime < nextErrorTimeout()
34+
) return;
35+
lastTime = e.timeStamp; nextErrorTimeout(true);
1436
postError(e.message);
1537
}
1638

0 commit comments

Comments
 (0)