From 534e96bd7b5140aa7e078c39140d2dd88e90e3a0 Mon Sep 17 00:00:00 2001 From: Julien Schneider Date: Tue, 30 Jan 2024 16:54:53 +0100 Subject: [PATCH 1/2] fix: various errors (#1416) --- .../create-project-form-page.component.ts | 7 ++++- .../src/lib/app-error-handler.ts | 29 +++++++++++++++---- .../lib/multi-language-textarea.component.ts | 20 ++++++------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/apps/dsp-app/src/app/project/create-project-form-page/create-project-form-page.component.ts b/apps/dsp-app/src/app/project/create-project-form-page/create-project-form-page.component.ts index 450b9dcc16..6d3f624e58 100644 --- a/apps/dsp-app/src/app/project/create-project-form-page/create-project-form-page.component.ts +++ b/apps/dsp-app/src/app/project/create-project-form-page/create-project-form-page.component.ts @@ -7,6 +7,7 @@ import { RouteConstants } from '@dasch-swiss/vre/shared/app-config'; import { ProjectService } from '@dasch-swiss/vre/shared/app-helper-services'; import { LoadProjectsAction } from '@dasch-swiss/vre/shared/app-state'; import { Store } from '@ngxs/store'; +import { finalize } from 'rxjs/operators'; @Component({ selector: 'app-create-project-form-page', @@ -64,10 +65,14 @@ export class CreateProjectFormPageComponent { selfjoin: true, status: true, }) + .pipe( + finalize(() => { + this.loading = false; + }) + ) .subscribe(projectResponse => { const uuid = ProjectService.IriToUuid(projectResponse.project.id); this._store.dispatch(new LoadProjectsAction()); - this.loading = false; this._router.navigate([RouteConstants.projectRelative, uuid]); }); } diff --git a/libs/vre/shared/app-error-handler/src/lib/app-error-handler.ts b/libs/vre/shared/app-error-handler/src/lib/app-error-handler.ts index 8d859a1db4..1e60654b1e 100644 --- a/libs/vre/shared/app-error-handler/src/lib/app-error-handler.ts +++ b/libs/vre/shared/app-error-handler/src/lib/app-error-handler.ts @@ -1,6 +1,7 @@ import { HttpErrorResponse } from '@angular/common/http'; import { ErrorHandler, Injectable } from '@angular/core'; import { ApiResponseError } from '@dasch-swiss/dsp-js'; +import { AppConfigService } from '@dasch-swiss/vre/shared/app-config'; import { NotificationService } from '@dasch-swiss/vre/shared/app-notification'; import { AjaxError } from 'rxjs/ajax'; @@ -8,22 +9,34 @@ import { AjaxError } from 'rxjs/ajax'; providedIn: 'root', }) export class AppErrorHandler implements ErrorHandler { - constructor(private _notification: NotificationService) {} + constructor( + private _notification: NotificationService, + private readonly _appConfig: AppConfigService + ) {} handleError(error: any): void { if (error instanceof ApiResponseError && error.error instanceof AjaxError) { // JS-LIB - this.handleHttpError(error.error, error.url); + this.handleGenericError(error.error, error.url); } else if (error instanceof HttpErrorResponse) { // ApiServices - this.handleHttpError(error, error.url); - } else { - // TODO in future: only display if environment === 'prod', now even local is configured as 'prod' + this.handleHttpErrorResponse(error); + } else if (this._appConfig.dspInstrumentationConfig.environment !== 'prod') { console.error(error); } } - private handleHttpError(error: HttpErrorResponse | AjaxError, url: string | null): void { + private handleHttpErrorResponse(error: HttpErrorResponse) { + if (error.status >= 400 && error.status < 500) { + const readableErrorMatch = error.error.error.match(/\((.*)\)$/); + this.displayNotification(readableErrorMatch[1]); + return; + } + + this.handleGenericError(error, error.url); + } + + private handleGenericError(error: HttpErrorResponse | AjaxError, url: string | null): void { let message: string; if (error.status === 0) { @@ -40,6 +53,10 @@ export class AppErrorHandler implements ErrorHandler { message = 'There is an error on our side. Our team is notified!'; } + this.displayNotification(message); + } + + private displayNotification(message: string) { this._notification.openSnackBar(message, 'error'); } } diff --git a/libs/vre/shared/app-string-literal/src/lib/multi-language-textarea.component.ts b/libs/vre/shared/app-string-literal/src/lib/multi-language-textarea.component.ts index 7273557f9a..592c98729d 100644 --- a/libs/vre/shared/app-string-literal/src/lib/multi-language-textarea.component.ts +++ b/libs/vre/shared/app-string-literal/src/lib/multi-language-textarea.component.ts @@ -27,16 +27,7 @@ import { MultiLanguageFormService } from './multi-language-form.service'; HumanReadableErrorPipe, ], template: ` -
- - - {{ lang }} - - +
+ + + {{ lang }} + +
Date: Wed, 31 Jan 2024 10:05:12 +0100 Subject: [PATCH 2/2] fix: display resource permission warning message (#1414) --- .../app/workspace/results/list-view/list-view.component.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/dsp-app/src/app/workspace/results/list-view/list-view.component.html b/apps/dsp-app/src/app/workspace/results/list-view/list-view.component.html index 1d118ca308..0cf227377b 100644 --- a/apps/dsp-app/src/app/workspace/results/list-view/list-view.component.html +++ b/apps/dsp-app/src/app/workspace/results/list-view/list-view.component.html @@ -38,9 +38,8 @@ (resourcesSelected)="emitSelectedResources($event)">
- -
+

Your search - {{search.query}} - did not match any documents.