intermediate commit

This commit is contained in:
lotte
2018-08-29 15:12:01 +02:00
parent 2cbe6a6d91
commit 777facf5cd
91 changed files with 1150 additions and 964 deletions

View File

@@ -1,10 +1,20 @@
import { of as observableOf, throwError as observableThrowError } from 'rxjs';
import {throwError as observableThrowError, Observable } from 'rxjs';
import { catchError, filter, map } from 'rxjs/operators';
import { Injectable, Injector } from '@angular/core';
import {
HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse,
HttpErrorResponse, HttpResponseBase
HttpErrorResponse,
HttpEvent,
HttpHandler,
HttpInterceptor,
HttpRequest,
HttpResponse,
HttpResponseBase
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { find } from 'lodash';
import { AppState } from '../../app.reducer';
@@ -76,11 +86,11 @@ export class AuthInterceptor implements HttpInterceptor {
// The access token is expired
// Redirect to the login route
this.store.dispatch(new RedirectWhenTokenExpiredAction('auth.messages.expired'));
return Observable.of(null);
return observableOf(null);
} else if (!this.isAuthRequest(req) && isNotEmpty(token)) {
// Intercept a request that is not to the authentication endpoint
authService.isTokenExpiring()
.filter((isExpiring) => isExpiring)
authService.isTokenExpiring().pipe(
filter((isExpiring) => isExpiring))
.subscribe(() => {
// If the current request url is already in the refresh token request list, skip it
if (isUndefined(find(this.refreshTokenRequestUrls, req.url))) {
@@ -98,8 +108,8 @@ export class AuthInterceptor implements HttpInterceptor {
}
// Pass on the new request instead of the original request.
return next.handle(newReq)
.map((response) => {
return next.handle(newReq).pipe(
map((response) => {
// Intercept a Login/Logout response
if (response instanceof HttpResponse && this.isSuccess(response) && (this.isLoginResponse(response) || this.isLogoutResponse(response))) {
// It's a success Login/Logout response
@@ -119,8 +129,8 @@ export class AuthInterceptor implements HttpInterceptor {
} else {
return response;
}
})
.catch((error, caught) => {
}),
catchError((error, caught) => {
// Intercept an error response
if (error instanceof HttpErrorResponse) {
// Checks if is a response from a request to an authentication endpoint
@@ -135,7 +145,7 @@ export class AuthInterceptor implements HttpInterceptor {
statusText: error.statusText,
url: error.url
});
return Observable.of(authResponse);
return observableOf(authResponse);
} else if (this.isUnauthorized(error)) {
// The access token provided is expired, revoked, malformed, or invalid for other reasons
// Redirect to the login route
@@ -144,7 +154,6 @@ export class AuthInterceptor implements HttpInterceptor {
}
// Return error response as is.
return observableThrowError(error);
}) as any;
})) as any;
}
}