Show possible remediation steps for known errors in a notification

Summary: This diff fires a notification with a remediation suggestion when the client takes a long time to connect back, for both WW and FS_ACCESS case

Reviewed By: mweststrate

Differential Revision: D23321067

fbshipit-source-id: 17ab93974e9571a0ba78af05c624eeb0522637c6
This commit is contained in:
Pritesh Nandgaonkar
2020-08-26 07:53:30 -07:00
committed by Facebook GitHub Bot
parent ce12c4e3df
commit dc4e224bfb
2 changed files with 38 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ import {Logger} from '../fb-interfaces/Logger';
import Client from '../Client'; import Client from '../Client';
import {UninitializedClient} from '../UninitializedClient'; import {UninitializedClient} from '../UninitializedClient';
import {addErrorNotification} from '../reducers/notifications'; import {addErrorNotification} from '../reducers/notifications';
import {CertificateExchangeMedium} from '../utils/CertificateProvider';
export default (store: Store, logger: Logger) => { export default (store: Store, logger: Logger) => {
const server = new Server(logger, store); const server = new Server(logger, store);
server.init(); server.init();
@@ -83,6 +83,28 @@ export default (store: Store, logger: Logger) => {
}, },
); );
server.addListener(
'client-unresponsive-error',
({
client,
medium,
deviceID,
}: {
client: UninitializedClient;
medium: CertificateExchangeMedium;
deviceID: string;
}) => {
store.dispatch(
addErrorNotification(
`Client ${client.appName} with device ${deviceID} took long time to connect back on the trusted channel.`,
medium === 'WWW'
? 'Verify that you are on lighthouse on your client and have a working internet connection. To connect to lighthouse on your client, use VPN. Follow this link: https://www.internalfb.com/intern/wiki/Ops/Network/Enterprise_Network_Engineering/ene_wlra/VPN_Help/Vpn/mobile/'
: 'Verify if your client is connected to Flipper and verify if there is no error related to idb.',
),
);
},
);
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
window.addEventListener('beforeunload', () => { window.addEventListener('beforeunload', () => {
server.close(); server.close();

View File

@@ -87,7 +87,7 @@ class Server extends EventEmitter {
logger: Logger; logger: Logger;
store: Store; store: Store;
initialisePromise: Promise<void> | null; initialisePromise: Promise<void> | null;
timeHandler: NodeJS.Timeout | undefined;
constructor(logger: Logger, store: Store) { constructor(logger: Logger, store: Store) {
super(); super();
this.logger = logger; this.logger = logger;
@@ -98,6 +98,7 @@ class Server extends EventEmitter {
this.insecureServer = null; this.insecureServer = null;
this.initialisePromise = null; this.initialisePromise = null;
this.store = store; this.store = store;
this.timeHandler = undefined;
} }
init() { init() {
@@ -276,6 +277,9 @@ class Server extends EventEmitter {
if (!payload.data) { if (!payload.data) {
return {}; return {};
} }
if (this.timeHandler) {
clearTimeout(this.timeHandler);
}
const clientData: ClientQuery & const clientData: ClientQuery &
ClientCsrQuery & {medium: number | undefined} = JSON.parse(payload.data); ClientCsrQuery & {medium: number | undefined} = JSON.parse(payload.data);
this.connectionTracker.logConnectionAttempt(clientData); this.connectionTracker.logConnectionAttempt(clientData);
@@ -410,6 +414,16 @@ class Server extends EventEmitter {
}), }),
metadata: '', metadata: '',
}); });
this.timeHandler = setTimeout(() => {
// Fire notification
this.emit('client-unresponsive-error', {
client,
medium: transformCertificateExchangeMediumToType(medium),
deviceID: result.deviceId,
});
}, 30 * 1000);
this.emit('finish-client-setup', { this.emit('finish-client-setup', {
client, client,
deviceId: result.deviceId, deviceId: result.deviceId,