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.

stop response in interceptors

See original GitHub issue

We use global response interceptor to do authentication: when the server returns 401, call vue-router to go to the Login route. After this point, the response should not be processed by any other interceptors or by user code any more. The problem is that, if I understand correctly according to the code, the response will be sent down though the interceptor chain and to user code after all. Can we have something like response.stop method to prevent it from further processing?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
JounQincommented, Aug 21, 2016

@steffans Hello, I’m sorry but I still don’t know how to stop response in interceptors.

When response is an error from server, how to handle the error globally and stop the Promise.resolve or Promise.reject?

I don’t want to handle the error like 40* specifically in every component.

6reactions
Centaurcommented, May 11, 2016

@listen-lavender In your top level component ( the first argument of router.start call), define:

created() {
  let self = this
  Vue.http.interceptors.push({
      response: function(response) {
         if(response.status === 401) {
           self.$route.router.go(...) 
         }
      }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to cancel current request in interceptor - Angular 4
If you wanna cancel requests after a certain timeout you can use rxjs timeout operator in intercepter, and it will work for every...
Read more >
Interceptors | Axios Docs
You can intercept requests or responses before they are handled by then or catch . ... If you need to remove an interceptor...
Read more >
Top 10 ways to use Interceptors in Angular - Medium
My ten favorite ways to use the interceptor in Angular. With examples of error handling, profiling, caching and more this list will inspire...
Read more >
Angular: Handle HTTP Errors using Interceptors
An error interceptor is a special type of interceptor which is used for handling errors that arise while making an HTTP request. The...
Read more >
Angular Interceptors to Manage HTTP Requests
Although interceptors can modify requests and responses, ... order should be used to avoid surprises when expecting a detailed response and ...
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