Skip to content

Instantly share code, notes, and snippets.

@stevermeister
Created July 19, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevermeister/e7cb2355a2b9d32f8e14bfb4f6b9f304 to your computer and use it in GitHub Desktop.
Save stevermeister/e7cb2355a2b9d32f8e14bfb4f6b9f304 to your computer and use it in GitHub Desktop.
import 'rxjs/add/operator/map';
export class JwtInterceptor implements HttpInterceptor {
constructor(public auth: AuthService) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).map((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
// do stuff with response if you want
}
}, (err: any) => {
if (err instanceof HttpErrorResponse {
if (err.status === 401) {
// redirect to the login route
// or show a modal
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment