draftbit / twitter-lite

A tiny, full-featured, flexible client / server library for the Twitter API

Home Page:https://npm.im/twitter-lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Twitter.post crashes silently

creativecreatorormaybenot opened this issue · comments

Use case

I use Twitter.post in order to post status updates, i.e. all my calls are as simple as:

const twitter = new Twitter(config)

await twitter.post('statuses/update', {
  status: tweet,
})

Problem

Whenever Twitter rejects my tweet because I am:

  • Exceeding 280 characters
  • Posting the same tweet twice in a row
  • Trying to post multiple tweets at once
  • etc.

twitter.post completely crashes my function. I get no errors. Instead, my logs look like this:

undefined
Function execution took 16076 ms, finished with status: 'error'

The undefined is only printed when twitter.post crashes.

Try-catch

The README says that I should be able to catch errors:

client
  .get("account/verify_credentials")
  .then(results => {
    console.log("results", results);
  })
  .catch(console.error);

However, this does not work for me. The catch block is simply never executed and I get the same undefined and function stopped behavior.

Reproduction

I know for a fact that this is exactly what happens. Both because I debugged this a lot and also because I have my Google Cloud Function set up with a CRON job - it just failed for 17 hours straight (see creativecreatorormaybenot/github-tracker#54).

You can view my code here (open source implementation). I have the twitter.post call in three other places and whenever it is called before the end of the function, e.g. here, the function will crash immediately and not save any data (which is how I can confirm that this is the actual behavior). Once I remove the twitter.post calls, everything works again. However, using try { await twitter.post(..) } catch {} does not help and neither does .catch.

Environment

I am running in a Google Cloud Functions environment using Node 12 and Typescript.