Guest User

Untitled

a guest
Oct 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. export class JwtRefreshInterceptor implements HttpInterceptor {
  2.  
  3. public constructor(
  4. private httpClient: HttpClient,
  5. ) { }
  6.  
  7. intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
  8. return next.handle(request).catch((error: HttpErrorResponse) => {
  9. if (error.status === 401) {
  10. return this.httpClient.post(environment.base_uri + 'auth/refresh', {}).flatMap((response) => {
  11. // get token from response.
  12. // put token in localstorage.
  13. // add token to the request.
  14.  
  15. // Do the request again with the new token.
  16. return next.handle(request);
  17. });
  18. }
  19.  
  20. return Observable.throw(error);
  21. });
  22. }
  23. }
  24.  
  25. Provider parse errors:
  26. Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
Add Comment
Please, Sign In to add comment