From ae10bd472d15a791bcf47d9f5bc1444d0d0fcbd0 Mon Sep 17 00:00:00 2001 From: Silke Date: Wed, 12 Jul 2023 15:33:06 +0200 Subject: [PATCH] fix: reload the application after an error occurred due to a changed pgid --- src/app/core/configuration.module.ts | 2 ++ src/app/core/utils/api-token/api-token.service.ts | 4 +++- .../utils/http-error/pgid-change.error-handler.ts | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/app/core/utils/http-error/pgid-change.error-handler.ts diff --git a/src/app/core/configuration.module.ts b/src/app/core/configuration.module.ts index 3f3ff108b1a..31a6029e6b3 100644 --- a/src/app/core/configuration.module.ts +++ b/src/app/core/configuration.module.ts @@ -5,6 +5,7 @@ import { createPaymentErrorHandler } from './utils/http-error/create-payment.err import { dataRequestErrorHandler } from './utils/http-error/data-request.error-handler'; import { editPasswordErrorHandler } from './utils/http-error/edit-password.error-handler'; import { LoginUserErrorHandler } from './utils/http-error/login-user.error-handler'; +import { pgidChangeErrorHandler } from './utils/http-error/pgid-change.error-handler'; import { requestReminderErrorHandler } from './utils/http-error/request-reminder.error-handler'; import { updateOciConfigurationErrorHandler } from './utils/http-error/update-oci-configuration.error-handler'; import { updatePasswordErrorHandler } from './utils/http-error/update-password.error-handler'; @@ -18,6 +19,7 @@ import { updatePasswordErrorHandler } from './utils/http-error/update-password.e { provide: SPECIAL_HTTP_ERROR_HANDLER, useValue: createPaymentErrorHandler, multi: true }, { provide: SPECIAL_HTTP_ERROR_HANDLER, useValue: updatePasswordErrorHandler, multi: true }, { provide: SPECIAL_HTTP_ERROR_HANDLER, useValue: updateOciConfigurationErrorHandler, multi: true }, + { provide: SPECIAL_HTTP_ERROR_HANDLER, useValue: pgidChangeErrorHandler, multi: true }, ], }) export class ConfigurationModule {} diff --git a/src/app/core/utils/api-token/api-token.service.ts b/src/app/core/utils/api-token/api-token.service.ts index 637de8fdb2e..5e6abcdc355 100644 --- a/src/app/core/utils/api-token/api-token.service.ts +++ b/src/app/core/utils/api-token/api-token.service.ts @@ -271,7 +271,9 @@ export class ApiTokenService { private isAuthTokenError(err: unknown) { return ( - err instanceof HttpErrorResponse && typeof err.error === 'string' && err.error?.toLowerCase().includes('token') + err instanceof HttpErrorResponse && + typeof err.error === 'string' && + (err.error.includes('AuthenticationToken') || err.error.includes('Unable to decode token')) ); } diff --git a/src/app/core/utils/http-error/pgid-change.error-handler.ts b/src/app/core/utils/http-error/pgid-change.error-handler.ts new file mode 100644 index 00000000000..489201e7c8f --- /dev/null +++ b/src/app/core/utils/http-error/pgid-change.error-handler.ts @@ -0,0 +1,11 @@ +import { SpecialHttpErrorHandler } from 'ish-core/interceptors/icm-error-mapper.interceptor'; + +// reload page when the pgid of the user has changed +export const pgidChangeErrorHandler: SpecialHttpErrorHandler = { + test: error => + error.error === 'Bad Request (The provided matrix parameter "pgid" does not match the authenticated user.)', + map: () => { + window.location.reload(); + return {}; + }, +};