How to Improve Error Handling and Resilience in Token Retrieval with Pipedream and Airtable?

This topic was automatically generated from Slack. You can find the original thread here.

Hello,

  const account = await pd.getAccountById(accountId, {
    include_credentials: true,
  });

How can I properly error handle this?

I’ve experienced two errors so far:

One time it threw with an error like “OAuth token could not be fetched”. And in that case auto-retry mechanism could recover this situation on my side.
But I’ve also experienced a situation when I got the token but afterwards received 401 from Airtable or Invalid authentication token. It might be a problem somewhere on my end, although it was a random occurence that I can’t replicate anymore so I think there’s a chance that the invalid token came from Pipedream.

Would be good to know how can I make the token retreival most resilient.

That is an issue on the Airtable side, if you get a 401 run your code to fetch the credentials again and it should work

Long story short is that Airtable invalidates previous tokens whenever a new refresh is requested, which is not a common practice

+1 to Andrew’s comment, and you can also check the health and dead attributes of the account before trying to use it.

Long story short is that Airtable invalidates previous tokens whenever a new refresh is requested, which is not a common practice
Ah, makes sense! it’s totally possible I was using one access token for too long in a long running task, thank you :pray:

check the health and dead attributes
Also a great idea, will implement both of these guards