[Error] s.finally is not a function
See original GitHub issueHi, 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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Flyrell thanks for answer, the warning is not showing but I will be trying again with another return statement to see what happens.
I was using node 10.22.0, what version you choose to upgrade ?