Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
How can I recreate a client and re-run automatically?

I have some code that looks like the following

const opts = {username: ..., password: ..., <misc>}
const client = new tmi.client(opts)

client.on('message', onMessageHandler)
client.on('connected', onConnectedHandler)

client.connect()

function onMessageHandler(props) {
    client.doStufF()
}

Basically, the code listens to an IRC chat and does stuff when a message comes through. Now, the code can fail on the .connect() and and on the .doStuff(), if the authentication expires. There is an API I can call with my saved refresh token to generate a new password, but right now I do this manually. I want to do this automatically.

The problem is, I'm not sure how to think about this pattern. Basically, I only know the token has expired once I make the call with invalid creds. But even if I write an error handler that catches the invalid credentials issue, how do I "go back" through all this code again to regenerate a new client with the new credentials and register the handlers again? I know this is a solved problem conceptually cause other packages offer this functionality already. I just want to implement it myself.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!