Added 405 error response check to interceptor

This commit is contained in:
Julius Gruber
2019-06-04 09:12:30 +02:00
parent 73c046974b
commit 3dfdc9bdc5

View File

@@ -33,6 +33,10 @@ export class AuthInterceptor implements HttpInterceptor {
constructor(private inj: Injector, private router: Router, private store: Store<AppState>) { } constructor(private inj: Injector, private router: Router, private store: Store<AppState>) { }
private is405AuthResponse(response: HttpResponseBase): boolean {
return response.status === 405;
}
private isUnauthorized(response: HttpResponseBase): boolean { private isUnauthorized(response: HttpResponseBase): boolean {
// invalid_token The access token provided is expired, revoked, malformed, or invalid for other reasons // invalid_token The access token provided is expired, revoked, malformed, or invalid for other reasons
return response.status === 401; return response.status === 401;
@@ -132,6 +136,12 @@ export class AuthInterceptor implements HttpInterceptor {
console.log('catchError operator in auth.interceptor was triggered'); console.log('catchError operator in auth.interceptor was triggered');
// Intercept an error response // Intercept an error response
if (error instanceof HttpErrorResponse) { if (error instanceof HttpErrorResponse) {
// Check for 405
if (this.is405AuthResponse(error)) {
console.log('the caught error is a 405');
}
// Checks if is a response from a request to an authentication endpoint // Checks if is a response from a request to an authentication endpoint
if (this.isAuthRequest(error)) { if (this.isAuthRequest(error)) {
console.log('catchError isAuthRequest=true'); console.log('catchError isAuthRequest=true');
@@ -140,6 +150,10 @@ export class AuthInterceptor implements HttpInterceptor {
// console.log('error: ', error); // console.log('error: ', error);
const location = error.headers.get('Location');// this line added while shibboleth dev const location = error.headers.get('Location');// this line added while shibboleth dev
console.log('error.headers.get("Location"): ', location); console.log('error.headers.get("Location"): ', location);
console.log('error headers: ', error.headers);
console.log('error', error);
// Create a new HttpResponse and return it, so it can be handle properly by AuthService. // Create a new HttpResponse and return it, so it can be handle properly by AuthService.
const authResponse = new HttpResponse({ const authResponse = new HttpResponse({
body: this.makeAuthStatusObject(false, null, error.error, location), body: this.makeAuthStatusObject(false, null, error.error, location),