Add RecurringError class for errors that should only be logged once per session

Summary:
Some errors such as UI errors should be logged whenever they occur, but some, such as those that occur when a device keeps trying to connect but can't, should not be.
This adds the class and replaces the top recurring errors with it.

Reviewed By: danielbuechele

Differential Revision: D8639448

fbshipit-source-id: f001aa1e90eae6d26a8dbfcd3175b51fc486eae9
This commit is contained in:
John Knox
2018-07-05 07:06:57 -07:00
committed by Facebook Github Bot
parent 0ddeb076bb
commit de353a7ed0
3 changed files with 34 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ import CertificateProvider from './utils/CertificateProvider';
import {RSocketServer, ReactiveSocket} from 'rsocket-core';
import RSocketTCPServer from 'rsocket-tcp-server';
import Client from './Client.js';
import {RecurringError} from './utils/errors';
const EventEmitter = (require('events'): any);
const invariant = require('invariant');
@@ -261,10 +262,11 @@ class ConnectionTracker {
this.connectionAttempts.set(key, entry);
if (entry.length >= this.connectionProblemThreshold) {
console.error(
`Connection loop detected with ${key}. Connected ${
entry.length
} times in ${(time - entry[0]) / 1000}s.`,
'ConnectionTracker',
new RecurringError(
`Connection loop detected with ${key}. Connected ${
this.connectionProblemThreshold
} times within ${this.timeWindowMillis / 1000}s.`,
),
);
}
}