Skip to main content
Best answer

I'm developing a trigger, and I get Token "is expired" sometimes. How do I fix this so the trigger does not throw errors?

  • December 29, 2020
  • 11 replies
  • 1634 views

alexb
Forum|alt.badge.img

Hi Everyone.

So I’m developing a Zapier integration against an Graphql Endpoint.

Sometimes Zapier sends me an email saying:

 

[Action Required]: Uh-oh! There’s a problem with one of your Zaps

 

When I look at the request, I can see that the underlying endpoint returned “Token is expired”. Now my question is, how do I fix this?

 

I’m using the “Code mode”, so I envision something like: 

const res = response.json;
if (res.expiredError) {
// What to do here?
} else {
return res.someDataPath;
}

But how do I “inform” the trigger that the token is expired?

 

 

 

Best answer by ikbelkirasan

Hi @alexb - Thanks for the extra details. Since the API is returning a 200 status code instead of 401 when the access token has expired, you should let Zapier know that it needs to refresh the access token.

You can achieve that using something like the following:

const res = response.json;
if (res.expiredError) {
// What to do here?
throw new z.errors.RefreshAuthError();
} else {
return res.someDataPath;
}

This would trigger Zapier to refresh the access token and retry the request.

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

11 replies

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • December 29, 2020

Hi @alexb - Are you using OAuth2 for the authentication?


alexb
Forum|alt.badge.img
  • Author
  • Tinkerer
  • December 29, 2020

Hi @ikbelkirasan.

Yes - sorry to mention. And it also seems like the integration “recovers”, but I still get the warning “action required” emails.

Can I somehow throw an error from inside the json response body? (I should maybe also mention that our GraphQl endpoint returns the token expired with status code 200)


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • Answer
  • December 29, 2020

Hi @alexb - Thanks for the extra details. Since the API is returning a 200 status code instead of 401 when the access token has expired, you should let Zapier know that it needs to refresh the access token.

You can achieve that using something like the following:

const res = response.json;
if (res.expiredError) {
// What to do here?
throw new z.errors.RefreshAuthError();
} else {
return res.someDataPath;
}

This would trigger Zapier to refresh the access token and retry the request.


alexb
Forum|alt.badge.img
  • Author
  • Tinkerer
  • December 29, 2020

Thanks for the quick reply @ikbelkirasan - what about other types of errors?


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • December 29, 2020

@alexb - You’re welcome! Can you specify what other errors you mean exactly?

Edit: You can see a list of errors defined in z.errors here: https://platform.zapier.com/cli_docs/docs#zerrors


alexb
Forum|alt.badge.img
  • Author
  • Tinkerer
  • December 29, 2020

Let’s say the Graphql Endpoint responded with a message saying the query was too costly? Or maybe the user did not have correct permissions? Maybe the server can’t tell the client in details, but just throws a “validation error”.


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • December 29, 2020

@alexb - I think in that case, you should handle that in your app logic either by retrying the request after a few seconds if that would solve the problem or just throw the error if the app can’t handle it.

In case you want the zap to remain active even if it encounters such errors, try throwing z.errors.HaltedError. It will stop the current operation, but the zap won’t be turned off.


alexb
Forum|alt.badge.img
  • Author
  • Tinkerer
  • December 29, 2020

Ok, I guess haltedError sounds good. Is there somewhere I can read more about the different z.errors?


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • December 29, 2020

Yup, I already included a link to that in a previous comment. Here you go https://platform.zapier.com/cli_docs/docs#zerrors


alexb
Forum|alt.badge.img
  • Author
  • Tinkerer
  • December 29, 2020

Sorry - my bad! thanks for the help!


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • December 29, 2020

No worries :)