Skip to content

Instantly share code, notes, and snippets.

@VicAv99
Created March 29, 2019 15:20
Show Gist options
  • Save VicAv99/7e45efee0abec94dbc40cb7ffbb7ba40 to your computer and use it in GitHub Desktop.
Save VicAv99/7e45efee0abec94dbc40cb7ffbb7ba40 to your computer and use it in GitHub Desktop.
// src/core/interceptors/blocker.interceptor.ts
import { Injectable } from ‘@angular/core’;
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from ‘@angular/common/http’;
import { MatSnackBar } from ‘@angular/material’;
import { Observable } from ‘rxjs’;
@Injectable({
providedIn: ‘root’
})
export class BlockerInterceptor implements HttpInterceptor {
constructor(private snackbar: MatSnackBar) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.body && req.body.blocker) {
const message = ‘Reminder: Your teammates are available for help’;
this.notify(message);
}
return next.handle(req);
}
private notify(message: string) {
this.snackbar.open(message, ‘Ok’, { duration: 3000 });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment