question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Error] s.finally is not a function

See original GitHub issue

Hi, I want to use the library in a react native application, I have a main axios request with the following

import axios from 'axios';

// interceptor
createAuthRefreshInterceptor(
    axios, 
    (failedRequest) => refreshToken(failedRequest, token, refresh_token),
    { skipWhileRefreshing: true }
  );

// original request
  axios.post(url, data).then(resp => {
    console.log('resp post', resp);
  }).catch(err => {
    console.log("error resp", err);
  })

with the refresh logic

const refreshAuthLogic = (failedRequest, token, refresh_token) => {
  return axios({
    method: 'POST',
    url: `${CUSTOMERS_API_URL}${V1}/client/customers/token-refresh`,
    headers: {
      refresh_token: `${refresh_token}`,
      Authorization: `Bearer ${token}`,
    },
  })
  .then(async (response) => {
    console.log('refresh token: ', response.data.data.access_token);
    await setToken(response.data.data.access_token);
    await setRefreshToken(response.data.data.refresh_token);
    failedRequest.response.config.headers['Authorization'] =
      'Bearer ' + response.data.data.access_token;
    return Promise.resolve();
  })
  .catch((err) => {
    console.log('refresh token error', JSON.stringify(err, null, 2));
  })
}

When the error 401 show up, the cath of the axios.post return this:

[TypeError: s.finally is not a function. (In 's.finally(function () {
          return n.unsetCache(e, u);
        })', 's.finally' is undefined)]

However the refresh logic executes fine and set the new token credentials, but the original request do not execute again.

What can be wrong ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
josera21commented, Jun 26, 2020

Hi @Flyrell thanks for answer, the warning is not showing but I will be trying again with another return statement to see what happens.

0reactions
josera21commented, Aug 24, 2020

I had this issue and it was because I was using an old version of Node. Support for .finally with Promises was only introduced in version 10: https://node.green/#ES2018-features-Promise-prototype-finally.

I was using node 10.22.0, what version you choose to upgrade ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

api.get(...).then(...).catch(...).finally is not a function
It looks like axios doesn't use new Promise internally - rather, it just returns a thenable, which is not guaranteed to have a...
Read more >
Firefox Promise - getting finally is not a function? : r/javascript
I ran it through firefox and see no error.
Read more >
Promise.prototype.finally() - JavaScript - MDN Web Docs
The finally() method of a Promise object schedules a function to be called when the promise is settled (either fulfilled or rejected).
Read more >
Using .then(), .catch(), .finally() to Handle Errors in Javascript ...
This is a “parsetime error” as the code cannot be parsed properly. try... catch can only catch errors which occur at runtime (after...
Read more >
JavaScript try/catch/finally Statement - W3Schools
finally statements combo handles errors without stopping JavaScript. The try statement defines the code block to run (to try). The catch statement defines...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found