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.