From 431232aeac84db70922f0d74dac87b786ec8a50e Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Mon, 21 Mar 2022 08:47:49 -0400 Subject: [PATCH] better error handling in filter refs #202 --- dist/server/logger.js | 14 ++--- dist/server/search-loader.js | 2 +- dist/server/twitter.js | 59 ++++++++++++++++--- src/client/components/Insights/ActionsList.js | 27 --------- src/server/twitter.js | 8 ++- 5 files changed, 65 insertions(+), 45 deletions(-) delete mode 100644 src/client/components/Insights/ActionsList.js diff --git a/dist/server/logger.js b/dist/server/logger.js index fdf6f328..e4883950 100644 --- a/dist/server/logger.js +++ b/dist/server/logger.js @@ -6,25 +6,23 @@ var _path = _interopRequireDefault(require("path")); var _winston = _interopRequireDefault(require("winston")); -var logger = _winston["default"].createLogger(); - var env = process.env.NODE_ENV; +var logger = _winston["default"].createLogger({ + format: _winston["default"].format.combine(_winston["default"].format.timestamp(), _winston["default"].format.json()) +}); + if (env === 'development') { logger.add(new _winston["default"].transports.Console({ level: 'debug' })); } else if (env === 'test') { - var logFile = _path["default"].join(__dirname, '..', '..', 'test.log'); - logger.add(new _winston["default"].transports.File({ - filename: logFile + filename: _path["default"].join(__dirname, '..', '..', 'test.log') })); } else { - var _logFile = _path["default"].join(__dirname, '..', '..', 'app.log'); - logger.add(new _winston["default"].transports.File({ - filename: _logFile + filename: _path["default"].join(__dirname, '..', '..', 'app.log') })); } diff --git a/dist/server/search-loader.js b/dist/server/search-loader.js index a642e590..caae71e3 100644 --- a/dist/server/search-loader.js +++ b/dist/server/search-loader.js @@ -294,7 +294,7 @@ var SearchLoader = /*#__PURE__*/function () { while (1) { switch (_context5.prev = _context5.next) { case 0: - _logger["default"].info("no more search results for search job ".concat(job.id)); + _logger["default"].info("stopping job ".concat(job.id)); _context5.next = 3; return this.db.updateSearchJob({ diff --git a/dist/server/twitter.js b/dist/server/twitter.js index a9ec76c1..9c20ed0b 100644 --- a/dist/server/twitter.js +++ b/dist/server/twitter.js @@ -295,9 +295,9 @@ var Twitter = /*#__PURE__*/function () { cb(null, [], null); } })["catch"](function (err) { - _logger["default"].error("error during search: ".concat(err)); + _logger["default"].error("error during search: ".concat(err.message)); - cb(err, null, null); + cb(err.message, null, null); }); }; @@ -562,19 +562,64 @@ var Twitter = /*#__PURE__*/function () { this.filter(cb); case 62: - _context5.next = 69; + _context5.next = 88; break; case 64: _context5.prev = 64; _context5.t2 = _context5["catch"](17); - _context5.next = 68; + + if (!(_context5.t2.message && _context5.t2.message.match(/stream unresponsive/i))) { + _context5.next = 73; + break; + } + + _logger["default"].warn("caught stream unresponsive error, sleeping and reconnecting"); + + _context5.next = 70; return (0, _utils.timer)(1000); - case 68: - _logger["default"].error("stream disconnected with error", _context5.t2); + case 70: + this.filter(cb); + _context5.next = 88; + break; + + case 73: + if (!(_context5.t2.message && _context5.t2.message.match(/ECONNREFUSED/))) { + _context5.next = 80; + break; + } + + _logger["default"].warn("caught connection refused, sleeping and reconnecting"); + + _context5.next = 77; + return (0, _utils.timer)(10000); + + case 77: + this.filter(cb); + _context5.next = 88; + break; + + case 80: + if (!(_context5.t2.message && _context5.t2.message.match(/ENOTFOUND/))) { + _context5.next = 87; + break; + } + + _logger["default"].warn("caught address not found, sleeping and reconnecting"); + + _context5.next = 84; + return (0, _utils.timer)(10000); + + case 84: + this.filter(cb); + _context5.next = 88; + break; + + case 87: + _logger["default"].error("unexpected stream error, unable to reconnect ".concat(_context5.t2)); - case 69: + case 88: case "end": return _context5.stop(); } diff --git a/src/client/components/Insights/ActionsList.js b/src/client/components/Insights/ActionsList.js deleted file mode 100644 index 4198eedc..00000000 --- a/src/client/components/Insights/ActionsList.js +++ /dev/null @@ -1,27 +0,0 @@ -import React, { Component } from 'react' -import PropTypes from 'prop-types' -import Tweet from '../Explore/Tweet' - -export default class ActionsList extends Component { - - render() { - const consent = this.props.actions.filter(a => a.archived === null && a.tweet) - return ( -
-
- {consent.map(action => ( -
- -
- ))} -
-
- ) - } - -} - -ActionsList.propTypes = { - actions: PropTypes.array -} - diff --git a/src/server/twitter.js b/src/server/twitter.js index b416506a..b432eb64 100644 --- a/src/server/twitter.js +++ b/src/server/twitter.js @@ -8,7 +8,7 @@ import emojiRegex from 'emoji-regex' import { AllHtmlEntities } from 'html-entities' import { flatten, EVERYTHING } from 'flatten-tweet' -const emojMatch = emojiRegex() +const emojiMatch = emojiRegex() const entities = new AllHtmlEntities() function decode(s) { @@ -262,10 +262,14 @@ export class Twitter { log.warn(`caught stream unresponsive error, sleeping and reconnecting`) await timer(1000) this.filter(cb) - } else if (error.match(/ECONNREFUSED/)) { + } else if (error.message && error.message.match(/ECONNREFUSED/)) { log.warn(`caught connection refused, sleeping and reconnecting`) await timer(10000) this.filter(cb) + } else if (error.message && error.message.match(/ENOTFOUND/)) { + log.warn(`caught address not found, sleeping and reconnecting`) + await timer(10000) + this.filter(cb) } else { log.error(`unexpected stream error, unable to reconnect ${error}`) }