Skip to content

Commit

Permalink
better error handling in filter refs #202
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed Mar 21, 2022
1 parent dc6f408 commit 431232a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 45 deletions.
14 changes: 6 additions & 8 deletions dist/server/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}));
}

Expand Down
2 changes: 1 addition & 1 deletion dist/server/search-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
59 changes: 52 additions & 7 deletions dist/server/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand Down Expand Up @@ -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();
}
Expand Down
27 changes: 0 additions & 27 deletions src/client/components/Insights/ActionsList.js

This file was deleted.

8 changes: 6 additions & 2 deletions src/server/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`)
}
Expand Down

0 comments on commit 431232a

Please sign in to comment.