Access tokens have a 1 hour lifespan. When the refresh flow is taken, Canvas will update the access token to a new value, reset the expiration timer, and return the new access token as part of the response. When refreshing tokens the user will not be asked to authorize the application again.
The resolution last time was that there’s not much else you’re able to do, that it may be related to a nuance with the Canvas API.
I wasn’t too bothered by that as it was just one every couple of days or so. But the more we build with Pipedream the more frequently this error occurs and it’s getting a little more frustrating.
I was hoping we could take another look at this issue?
I have some workflows using the same API on the Zapier Developer Platform and have not had this issue happen at all, same with a custom solution we have running in PHP.
Is anyone able to help me explore this a little deeper? I am happy to go to Canvas tech support and seek assistance but I don’t have much technical data and can’t see the code used to authenticate it so it’s a little difficult for me to give them much more than “intermittent 401s.”
Would really love to see this one running a bit more smoothly!
@accellier, could you try adding the code to retry the request if it failed with status 401? Also which API you’re using? Maybe you can create a ticket here to request the action?
Speaking out of my guts, I understand Pipedream components perform exponential backoff retrying failed request, before giving app. Perhaps the config on this strategy could be twaked so that it can retry taking the time enough for the access token to be refreshed properly instead of bailing out quickly.
I guess the persistence and frequency of this issue lead me to see if there was a way to resolve it in the way the authentication works.
To be honest with you I was being lazy and not handling for this error on our side. So I have used the following approach. Do you think it will be okay?
try {
return await canvasRequest(requestData)
} catch (error) {
if (error.response.status === 401) {
//try again if it's a 401...
return await canvasRequest(requestData)
} else {
throw error
}
}
Yes I think there is likely a better way to do this, for example. I think you should wait certain interval before doing the retry. Pipedream components leverage the "async-retry" npm library, why don’t give a try?
You can take a look at the several Pipedream components, for instance, I myself was involved in the Mailchimp app.
Check how we wrap the request we want to be attempted, in this case ailchimp.lists.createListWebhook inside an “_withRetries”
@accellier sorry to hear this issue is still plaguing you! I agree we should ideally be handling any refresh inconsistencies as a part of the auth process, so we’ll try to look into this again.
In the meantime though, there are a copule options to work around the 401s you’re seeing.
Like you saw, we recently rolled out auto-retry for the Advanced plan in workspaces (a new version of “orgs”). If you’re interested in checking it out, you can create a new workspace (top left of your Pipedream account), then you’ll have the option to enable auto-retry in any workflow after you upgrade to the Advanced plan.
Thanks Danny! I’m the only Pipedream user in our org so we don’t have a need for workspaces. $.flow.rerun() looks like a simple work-around in this case - thank you!