Created
June 11, 2021 12:40
-
-
Save amilamen/48351c6f2647065f1b0a2802a1471082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
intercept(request: HttpRequest<any>, next: HttpHandler) { | |
return from(this.storageService.getToken()).pipe( | |
switchMap((token) => { | |
if (token) { | |
request = request.clone({ | |
headers: request.headers.set("Authorization", "Bearer " + token), | |
}); | |
} | |
request = request.clone({ | |
headers: request.headers.set("Accept", "application/json"), | |
}); | |
return next.handle(request).pipe( | |
map((event: HttpEvent<any>) => { | |
if (event instanceof HttpResponse) { | |
} | |
return event; | |
}), | |
catchError((error: HttpErrorResponse) => { | |
return throwError(error); | |
}) | |
); | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment