Skip to main content

Whenever I try to throw RefreshAuthError, it shows it is unhandled instead of calling the refreshAccessToken. 

This is the error stack

 

Unhandled error: RefreshAuthError: 

What happened:

  Starting POST request to {url}

  Received 400 code from {url} after 1956ms

  Received content "

{

 "response":{

   "action":"action",

   "error":{

     "code":8535,

     "message":"Invalid Oauthtoken"

  

RefreshAuthError

    at afterResponse (/zapier/sample/index.js:16:15)

    at Object.collector.then (/zapier/sample/node_modules/zapier-platform-core/src/middleware.js:80:37)

    at bound (domain.js:395:14)

    at Object.runBound (domain.js:408:12)

    at Object.tryCatcher (Documents/zapier/sample/node_modules/bluebird/js/release/util.js:16:23)

    at Promise._settlePromiseFromHandler (/zapier/sample/node_modules/bluebird/js/release/promise.js:547:31)

    at Promise._settlePromise (/zapier/sample/node_modules/bluebird/js/release/promise.js:604:18)

    at Promise._settlePromise0 (/zapier/sample/node_modules/bluebird/js/release/promise.js:649:10)

    at Promise._settlePromises (/zapier/sample/node_modules/bluebird/js/release/promise.js:729:18)

    at _drainQueueStep (/zapier/sample/node_modules/bluebird/js/release/async.js:93:12)

    at _drainQueue (/zapier/sample/node_modules/bluebird/js/release/async.js:86:9)

    at Async._drainQueues (/zapier/sample/node_modules/bluebird/js/release/async.js:102:5)

    at Immediate.Async.drainQueues las _onImmediate] (/zapier/sample/node_modules/bluebird/js/release/async.js:15:14)

    at runCallback (timers.js:705:18)

    at tryOnImmediate (timers.js:676:5)

    at processImmediate (timers.js:658:5)

    at process.topLevelDomainCallback (domain.js:120:23)

    1) should create an object

What platform are you using to build this...CLI or Visual Builder?  What is the Authentication method required (OAuth, Token, Basic)?  Can you provide a snippet of your code to look at?

 

David


Hi @yttest!

I wanted to check in with you on this one, since we didn't hear back after that last message. Did you still need help here or were you able to resolve things? Please let us know :)


heya, I'm also having this issue @yttest  did you find a solution for this? 

I'm using the CLI for Oauth2 

just calling a      

throw new z.errors.RefreshAuthError();

and expecting it to be handled on zapiers end by calling the refreshAccessToken in the oauth2Config provided in the index. Just double checking my understanding is correct :) 


Hi there, I’ve got the same problem, session based authentication. All works ok until the session token expires. CLI app.

 

I get -

== Log

Unhandled error: RefreshAuthError:

What happened:

  Starting POST request to https://sremoved]

  Received 403 code from https://premoved] after 477ms

  Received content ""

  

RefreshAuthError

 

The authentication.js is attached urls removed. Any help would be gratefully received.

 

Best

 

Giles


@ghorwitchsmith - Try adding skipThrowForStatus: true in your request options then in your after middleware, call response.throwForStatus() after the if statement that handles the 403 error. Hope this helps.


@ikbelkirasan Really appreciate you coming back to me. I was not clear on where you suggesting the skipThrowForStatus:true needs to go? 

 

Best

 

Giles


@ghorwitchsmith Hi Giles, sure thing - It should be added in your z.request options.

z.request({
// ...method, url, headers,...etc
skipThrowForStatus: true,
});

 


Thanks @ikbelkirasan appreciate it, I’ve added in authentication.js in the beforeRequest so I don’t have to add everywhere (hopefully) and then the afterResponse. Hopefully this works, I’ve uploaded to Zapier, just need to wait for the session to time out! - 

const includeSessionKeyHeader = (request, z, bundle) => {

if (bundle.authData.sessionKey) {

request.headers = request.headers || {};

request.headers.'Authorization'] = `Bearer ${bundle.authData.sessionKey}`;

}

request.skipThrowForStatus = true; // deal with 403 our selves

 

return request;

};

 

// Refresh the session if we have a key and we are getting a 403

const sessionRefreshIf403 = (response, z, bundle) => {

if (bundle.authData.sessionKey) {

if (response.status === 403) {

// throw new z.errors.RefreshAuthError(); // ask for a refresh & retry

response.throwForStatus();

}

}

return response;

};

 


@ikbelkirasan Really appreciate your input, sadly I’m still getting errors when the token expires -

 

== Log
Unhandled error: ResponseError: {"status":403,"headers":{"content-type":null},"content":"","request":{"url":"https://removed"}}
ResponseError: {"status":403,"headers":{"content-type":null},"content":"","request":{"url":"https://removed"}}
    at throwForStatus (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/http-middlewares/after/throw-for-status.js:7:11)
    at Object.outResp.throwForStatus (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/http-middlewares/after/prepare-response.js:44:36)
    at sessionRefreshIf403 (:censored:9:d1ba0cf2aa:/authentication.js:61:16)
    at Object.collector.then.newOutput (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:80:37)
From previous event:
    at afters.reduce (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:77:26)
    at Array.reduce (<anonymous>)
    at afterMiddleware (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:76:21)
    at Object.resolve.then.then.output (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:94:18)
From previous event:
    at Object.beforeMiddleware.then.newInput (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:92:10)
From previous event:
    at input (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:89:45)
    at loadApp.then.appRaw (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:215:18)
    at bound (domain.js:402:14)
    at runBound (domain.js:415:12)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:126:23)
From previous event:
    at Domain.handlerDomain.run (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:200:10)
    at Domain.run (domain.js:349:14)
    at Runtime.handler (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:192:19)
    at Runtime.handleOnce (:censored:12:bb66ff632a:/Runtime.js:66:25)
== Version
0.0.1
== Step
== Timestamp
2021-03-24T17:08:56+00:00

 

Any help would be appreciated!


Hi @ghorwitchsmith - Hmm can you tell me which zapier-platform-core version you are using? 


Hi @ikbelkirasan 

I was on 9.4.0, I thought I was on 10.2.0! I spotted this last night, just had a mad day at work today. So I’ve updated the dependency, I’ve also redone the authentication as per the attached authentication.js.txt, with the updated index.js.txt.

 

I removed all of the throwForStatus as I’ve read that relates to 9.4 and also removed the skipThrowForStatus.

 

I do still get an unhandled exception in the logs every hour but the zaps are not longer failing, which is a relief. Error in logexample.txt

 

Is the error in the logs to be expected?

 

Thanks again for your help.

 

Best

 

Giles