24
bizmatch/src/app/services/globalErrorHandler.ts
Normal file
24
bizmatch/src/app/services/globalErrorHandler.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { ErrorHandler, Injectable } from '@angular/core';
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
|
||||
@Injectable()
|
||||
export class GlobalErrorHandler implements ErrorHandler {
|
||||
constructor(private keycloakService: KeycloakService) {}
|
||||
|
||||
handleError(error: any): void {
|
||||
// Prüfe, ob es sich um einen HttpErrorResponse handelt
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
// Prüfe, ob es ein 401 Unauthorized Fehler ist
|
||||
if (error.status === 401) {
|
||||
// Führe den Login-Prozess über Keycloak aus
|
||||
this.keycloakService.login({
|
||||
redirectUri: window.location.href, // oder eine benutzerdefinierte URL
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Weiterhin normale Fehlerbehandlung
|
||||
console.error('Ein Fehler ist aufgetreten:', error);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ export class KeycloakInitializerService {
|
||||
initOptions: {
|
||||
onLoad: 'check-sso',
|
||||
silentCheckSsoRedirectUri: (<any>window).location.origin + '/assets/silent-check-sso.html',
|
||||
// flow: 'implicit',
|
||||
},
|
||||
bearerExcludedUrls: ['/assets'],
|
||||
});
|
||||
this.initialized = true;
|
||||
resolve(true);
|
||||
@@ -30,35 +30,5 @@ export class KeycloakInitializerService {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
// if (this.initialized) {
|
||||
// return;
|
||||
// }
|
||||
// logger.info(`###>calling keycloakService init ...`);
|
||||
// const authenticated = await this.keycloakService.init({
|
||||
// config: {
|
||||
// url: environment.keycloak.url,
|
||||
// realm: environment.keycloak.realm,
|
||||
// clientId: environment.keycloak.clientId,
|
||||
// },
|
||||
// initOptions: {
|
||||
// onLoad: 'check-sso',
|
||||
// silentCheckSsoRedirectUri: (<any>window).location.origin + '/assets/silent-check-sso.html',
|
||||
// // flow: 'implicit',
|
||||
// },
|
||||
// // initOptions: {
|
||||
// // pkceMethod: 'S256',
|
||||
// // redirectUri: environment.keycloak.redirectUri,
|
||||
// // checkLoginIframe: false,
|
||||
// // },
|
||||
// });
|
||||
// logger.info(`+++>authenticated: ${authenticated}`);
|
||||
// const token = await this.keycloakService.getToken();
|
||||
// logger.info(`--->${token}`);
|
||||
|
||||
// this.initialized = true;
|
||||
}
|
||||
|
||||
// isInitialized(): boolean {
|
||||
// return this.initialized;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ export class ListingsService {
|
||||
}
|
||||
}
|
||||
async deleteBusinessListing(id: string) {
|
||||
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/business/${id}`));
|
||||
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/business/listing/${id}`));
|
||||
}
|
||||
async deleteCommercialPropertyListing(id: string, imagePath: string) {
|
||||
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/commercialProperty/${id}/${imagePath}`));
|
||||
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/commercialProperty/listing/${id}/${imagePath}`));
|
||||
}
|
||||
async removeFavorite(id: string, listingsCategory?: 'business' | 'commercialProperty') {
|
||||
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/favorites/${id}`));
|
||||
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/favorite/${id}`));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user