Prevent extensive logging of failed network requests
Summary: If the browser makes a network request, and it fails, this is _always_ logged to the console, despite any error handling being in place. (see https://stackoverflow.com/questions/43012334/silence-neterr-connection-refused) This diffs doesn't use the browser network stack, but the node network stack instead, which doesn't suffer from the same fate. Reviewed By: passy Differential Revision: D19995684 fbshipit-source-id: 4ffc12b820620c5310c140c1a3af63e5d2053a50
This commit is contained in:
committed by
Facebook Github Bot
parent
474ff78bd8
commit
a05b8d1ba2
@@ -12,6 +12,7 @@ import {Logger} from '../fb-interfaces/Logger';
|
|||||||
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice';
|
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice';
|
||||||
import MetroDevice from '../devices/MetroDevice';
|
import MetroDevice from '../devices/MetroDevice';
|
||||||
import {ArchivedDevice} from 'flipper';
|
import {ArchivedDevice} from 'flipper';
|
||||||
|
import http from 'http';
|
||||||
|
|
||||||
const METRO_PORT = 8081;
|
const METRO_PORT = 8081;
|
||||||
const METRO_HOST = 'localhost';
|
const METRO_HOST = 'localhost';
|
||||||
@@ -22,13 +23,26 @@ const QUERY_INTERVAL = 5000;
|
|||||||
const METRO_DEVICE_ID = 'metro'; // there is always only one activve
|
const METRO_DEVICE_ID = 'metro'; // there is always only one activve
|
||||||
|
|
||||||
async function isMetroRunning(): Promise<boolean> {
|
async function isMetroRunning(): Promise<boolean> {
|
||||||
try {
|
return new Promise(resolve => {
|
||||||
// TODO: this prints a log error without connection, fix that
|
// We use Node's http library, rather than fetch api, as the latter cannot supress network errors being shown in the devtools console
|
||||||
const contents = await (await global.fetch(METRO_URL)).text();
|
// which generates a lot of noise
|
||||||
return METRO_MESSAGE.some(msg => contents.includes(msg));
|
http
|
||||||
} catch (e) {
|
.get(METRO_URL, resp => {
|
||||||
return false;
|
let data = '';
|
||||||
}
|
resp
|
||||||
|
.on('data', chunk => {
|
||||||
|
data += chunk;
|
||||||
|
})
|
||||||
|
.on('end', () => {
|
||||||
|
const isMetro = METRO_MESSAGE.some(msg => data.includes(msg));
|
||||||
|
resolve(isMetro);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on('error', err => {
|
||||||
|
console.debug('Could not connect to METRO ' + err);
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function registerDevice(
|
async function registerDevice(
|
||||||
|
|||||||
Reference in New Issue
Block a user