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.

Interceptor not fired from created hook on full page reload

See original GitHub issue

In this standalone project https://github.com/rightaway/demo you’ll see that the I use a created hook to make an HTTP request using this.$http.get (https://github.com/rightaway/demo/blob/master/src/Home.vue#L11).

However, the interceptor https://github.com/rightaway/demo/blob/master/src/index.js#L16 doesn’t get fired when I load the page from a browser reload. But if I click to another link on that page (e.g. Login) and then click back to the main link Home, the interceptor does get fired and the console.log occurs.

Why does the interceptor not fire on initial page load?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
pzanitticommented, Oct 13, 2016

That’s because the interceptor is added after Home component’s created() hook runs.

You can either place the interceptor before const vm = new Vue({ or mount the vm after the interceptor:

const vm = new Vue({
  router,
  store,
})

Vue.http.interceptors.push((request, next) => {
  console.log('before-request')
  next()
});

vm.$mount('#app');

The console then shows:

dev-server.js:60 [HMR] Waiting for update signal from WDS...
index.js:16 before-request
client?cbff:37 [WDS] Hot Module Replacement enabled.
0reactions
PeterSengcommented, Apr 24, 2018

@pzanitti Thanks.Your answer helps me also.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interceptor not executed when I refresh my page using ...
I am using JWT Authentication(Spring Boot Security) and on each click my interceptor is called to set the token before the request is...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
Once the page is loaded, the application fetches the todo items, and everything is working as expected.
Read more >
How to use Axios interceptors to handle API error responses
One way to solve this problem, is to handle it when you do the request in your code, so if you have an...
Read more >
Refreshing Tokens With Axios Interceptors - YouTube
Implementing JWT access and refresh token authentication with Django & React using axios interceptor method. This video is a continuation of ...
Read more >
Refreshing Tokens With Fetch | Custom Interceptor - YouTube
Refresh JSON Web Tokens by building a custom wrapper around fetch calls in order to update tokens before OR after responsesSource Code: ...
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