X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fauth%2Fauth-interceptor.service.ts;h=bb236bf8ceabff505747ecf0c2730f284119f5ec;hb=db400f447a9f7aae1c56fa25396e93069744483f;hp=efcfc452b654d9ac6ebb91f94deb0d32124a82c5;hpb=54c3a22faa04bf13eea37f39be9149fc5eb95737;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/auth/auth-interceptor.service.ts b/client/src/app/shared/auth/auth-interceptor.service.ts index efcfc452b..bb236bf8c 100644 --- a/client/src/app/shared/auth/auth-interceptor.service.ts +++ b/client/src/app/shared/auth/auth-interceptor.service.ts @@ -1,14 +1,8 @@ +import { Observable, throwError as observableThrowError } from 'rxjs' +import { catchError, switchMap } from 'rxjs/operators' import { Injectable, Injector } from '@angular/core' -import { - HttpInterceptor, - HttpRequest, - HttpEvent, - HttpHandler, HTTP_INTERCEPTORS -} from '@angular/common/http' -import { Observable } from 'rxjs/Observable' - +import { HTTP_INTERCEPTORS, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http' import { AuthService } from '../../core' -import 'rxjs/add/operator/switchMap' @Injectable() export class AuthInterceptor implements HttpInterceptor { @@ -27,22 +21,26 @@ export class AuthInterceptor implements HttpInterceptor { // Pass on the cloned request instead of the original request // Catch 401 errors (refresh token expired) return next.handle(authReq) - .catch(err => { - if (err.status === 401 && err.error && err.error.code === 'invalid_token') { - return this.handleTokenExpired(req, next) - } - - return Observable.throw(err) - }) + .pipe( + catchError(err => { + if (err.status === 401 && err.error && err.error.code === 'invalid_token') { + return this.handleTokenExpired(req, next) + } + + return observableThrowError(err) + }) + ) } private handleTokenExpired (req: HttpRequest, next: HttpHandler): Observable> { return this.authService.refreshAccessToken() - .switchMap(() => { - const authReq = this.cloneRequestWithAuth(req) + .pipe( + switchMap(() => { + const authReq = this.cloneRequestWithAuth(req) - return next.handle(authReq) - }) + return next.handle(authReq) + }) + ) } private cloneRequestWithAuth (req: HttpRequest) {