Skip to content

Commit

Permalink
fix: add exception handling to tweet fetch script
Browse files Browse the repository at this point in the history
  • Loading branch information
codeimpossible authored Jul 14, 2023
1 parent c567b7e commit 550ed7f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ if (args.length === 0) {
process.exit(1);
}

process.on('uncaughtException', function (err) {
if (err) {
console.log(`uncaught exception ${err}`, err.stack);
process.exit(1);
}
});

const credentialsFile = path.resolve(__dirname, '../credentials.json');
if (fs.existsSync(credentialsFile)) {
const credentalsJson = fs.readFileSync(credentialsFile).toString();
Expand All @@ -23,10 +30,14 @@ if (fs.existsSync(credentialsFile)) {

(async function Main(screen_name, since) {
since = since || -1;
const tweets = await fetchTweets(screen_name, since);
if (tweets.length > 0 && !tweets.errors) {
await storeTweets(tweets);
console.log(`🐣 stored ${tweets.length} tweets.`);
try {
const tweets = await fetchTweets(screen_name, since);
if (tweets.length > 0 && !tweets.errors) {
await storeTweets(tweets);
console.log(`🐣 stored ${tweets.length} tweets.`);
}
} catch (e) {
console.log(`exception while fetching tweets. ${e}`, e.stack);
}
process.exit(0);
})(args[0], index.latestId);

0 comments on commit 550ed7f

Please sign in to comment.