Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Asynchrone issue inside angular interceptor

I have an interceptor that checks if a condition is true it opens a snackbar and wait for the user to click a button ( so subscribe to button observer event ). If false: it returns the request.

intercept(req: HttpRequest<any>,
  next: HttpHandler): Observable<HttpEvent<any>> {
  if (this.rightsService.actualCookies && this.cookiesService.get('cookie') !== this.rightsService.actualCookies) {
    const snackBarRef = this.snackBar.open('Session expired', 'refresh');
    snackBarRef.onAction().subscribe(() => {
      window.location.pathname = window.location.pathname.split('/')[0]
    });
  }
  else {
      return next.handle(req);
  }
}

My issue is that if condition is true the interceptor don't wait for the observable and I think that it returns a void response. thats why other interceptors are getting error :

Cannot read property 'pipe' of undefined

in line

intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
   return next.handle(request).pipe(

My question is how to disable interceptor to return a value if (this.rightsService.actualCookies && this.cookiesService.get('cookie') !== this.rightsService.actualCookies) is true

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

your interceptor MUST return something:

intercept(req: HttpRequest<any>,
  next: HttpHandler): Observable<HttpEvent<any>> {
  if (this.rightsService.actualCookies && this.cookiesService.get('cookie') !== this.rightsService.actualCookies) {
    const snackBarRef = this.snackBar.open('Session expired', 'refresh');
    // angular will subscribe. do whatever you need to do in tap.
    return snackBarRef.onAction().pipe(tap(() => {
      window.location.pathname = window.location.pathname.split('/')[0]
    }));
  }
  else {
      return next.handle(req);
  }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!