Following the st-schema example closely, refreshing expired token logic results in exception

I have a sample st-schema connector going and running, using Node and the st-schema node package, latest version (1.5.2).

I write out callback auth tokens to a file so that if I stop and restart, I can re-fetch them and use them. This was working out OK. I see eventually it needed to refresh the token and thus jumped into the refresh logic of st-schema:

updateState(callbackUrls, callbackAuth, deviceState, refreshedCallback) {

return this[doUpdateState](callbackUrls.stateCallback, callbackAuth.accessToken, deviceState).then(res => {
  if (res.status === 401 && refreshedCallback) {

    return new RefreshTokenRequest(this.clientId, this.clientSecret).getCallbackToken(
        callbackUrls.oauthToken,
        callbackAuth.refreshToken
    ).then(refreshResponse => {
      refreshedCallback(refreshResponse.callbackAuthentication);

      return this[doUpdateState](callbackUrls.stateCallback, refreshResponse.callbackAuthentication.accessToken, deviceState)
          .then(checkFetchStatus)
    })
  }

  return checkFetchStatus(res)
})

}

I have a refreshedCallback passed in that just logs something so that it proceeds to refresh the token. I know it’s been called. However when it gets down to checkFetchStatus() I get an exception:

Uncaught Error UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason β€œ[object Object]”.
at getErrorWithoutStack (internal/process/promises:321:15)
at generateUnhandledRejectionError (internal/process/promises:341:15)
at processPromiseRejections (internal/process/promises:287:24)
at processTicksAndRejections (internal/process/task_queues:96:32)
promises:321

Does anyone have an idea why this might be happening, or if there is any additional programming required to handle refreshing tokens?

Thanks!

Basically, a call to refresh the token at https://c2c-us.smartthings.com/oauth/token gives a 401 which is uncaught.

Sorry for the delay. Could you please replicate the issue and send me the timestamp along with your appID? please send the information to us at build@smartthings.com to check what is happening.

Hi. Will do. Thanks.

1 Like