Open crivasr opened 3 years ago
Same problem here.
I have been using the API for a good month (or so) but from the past couple of days in every five minutes (starting from launching my script) I get the same Error: aborted
from my console logs. After some searching off the internet, I found that this error is thrown when there had been a problem with its TCP peer connection (a connection error basically).
My current understanding of this is that the API server itself is loaded to the brim (meaning there are too many requests happening at once and to save itself the server shuts off your connection to it). Given that its latest version was published three years ago, it is somewhat understandable that there would be many developers using it and problems with the API package itself.
Currently, what I did to mitigate but not completely solve it was to put the stream listener inside a try catch
statement and have the script run using PM2 (if the try catch
statement isn't enough at least I don't have to worry about manually re-launching the script). Sadly there is no error
event emitter from the API (although there is disconnect
and warning
emitters. I don't really think the emitters can do much help with this error, plus, I haven't really used those emitters).
Hopefully, this would get fixed, or at least they would add an error
event emitter so that it doesn't abruptly end the process running.
Same issue here, try catch did do the trick
Here is some wrapper code with try/catch+a recursive function which I think solves this problem.
const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
async function startRecursiveStream(i){
if(i>0){
console.log("Starting stream...")
try{
let stream = T.stream('statuses/filter', { track: '@metaforecast' })
stream.on('tweet', answerWithMetaforecastScreenshot)
}catch(error){
sleep(1000) // Be a good citizen
console.log("Most ot the time, the below will be a harmless reconnection error")
console.log(error)
startRecursiveStream(i-1)
}
}else{
console.log("Too many errors. Shutting down.")
throw(new Error("Continued failure to connect to stream.")) // Heroku application should restart after fatal error.
}
}
startRecursiveStream(10)
Hello, I have this issue and wrapping it in a try catch block didn't change anything.
I'm using this module for a couple month and since yesterday I think, or maybe even before that, I'm getting this error after a couple minutes of running the program:
here is my code: