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?

  • 29 December 2020
  • 11 replies
  • 1413 views

Userlevel 2
Badge

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?

 

 

 

icon

Best answer by ikbelkirasan 29 December 2020, 20:26

View original

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

Userlevel 7
Badge +12

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

Userlevel 2
Badge

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)

Userlevel 7
Badge +12

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.

Userlevel 2
Badge

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

Userlevel 7
Badge +12

@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

Userlevel 2
Badge

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”.

Userlevel 7
Badge +12

@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.

Userlevel 2
Badge

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

Userlevel 7
Badge +12

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

Userlevel 2
Badge

Sorry - my bad! thanks for the help!

Userlevel 7
Badge +12

No worries :)