Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda