mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
308d63fe93
Summary: When metro is not running, D15559151 caused infinite exceptions (fetch threw an error if it couldn't connect to localhost:8081) which affected UI. Swallow those errors and everything works well, with or without metro. Reviewed By: yungsters Differential Revision: D15588623 fbshipit-source-id: d170ea82478545836a7a22a228196c9778e93ef0
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const getDevServer = require('./getDevServer');
|
|
|
|
let ID = 0;
|
|
|
|
function logToConsole(
|
|
level: 'trace' | 'info' | 'warn' | 'log',
|
|
data: Array<mixed>,
|
|
) {
|
|
let body;
|
|
try {
|
|
body = JSON.stringify({id: ID++, level, data});
|
|
} catch (error) {
|
|
body = JSON.stringify({id: ID++, level, data: [error.message]});
|
|
}
|
|
fetch(getDevServer().url + 'log-to-console', {
|
|
method: 'POST',
|
|
body,
|
|
}).catch(e => {
|
|
// ...Oh well!
|
|
// If metro is running, logs should be sent to metro.
|
|
// If metro is NOT running, this will throw an exception every time... and
|
|
// those exceptions will be caught and logged, which will throw another
|
|
// exception, etc, causing infinite exception loop which affects UI perf.
|
|
// If we swallow silently here, that won't happen.
|
|
});
|
|
}
|
|
|
|
module.exports = logToConsole;
|