From 2f5545ba5da9f2e85569bc3c2c5d004c5bf97843 Mon Sep 17 00:00:00 2001 From: Julien Schneider Date: Wed, 31 Jan 2024 14:00:57 +0100 Subject: [PATCH 1/4] fix: improve error handler responses --- .../src/lib/app-error-handler.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 45e6ec9c4c..487f9a4983 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 @@ -28,12 +28,20 @@ export class AppErrorHandler implements ErrorHandler { private handleHttpErrorResponse(error: HttpErrorResponse) { if (error.status === 400) { - const readableErrorMatch = error.error.error.match(/dsp\.errors\.BadRequestException:(.*)$/); - this.displayNotification(readableErrorMatch[1]); - return; - } else if (error.status >= 400 && error.status < 500) { - const readableErrorMatch = error.error.error.match(/\((.*)\)$/); - this.displayNotification(readableErrorMatch[1]); + if (error.error?.error) { + const badRequestRegexMatch = error.error.error.match(/dsp\.errors\.BadRequestException:(.*)$/); + + if (badRequestRegexMatch) { + this.displayNotification(badRequestRegexMatch[1]); + } + } else if (typeof error.error === 'string') { + const invalidRequestRegexMatch = error.error.match(/\((.*)\)$/); + if (invalidRequestRegexMatch) { + this.displayNotification(invalidRequestRegexMatch[1]); + } + } else if (error.error.message) { + this.displayNotification(error.error.message); + } return; } From f5884682fd5fcbb2d1bdb60d1d7e29555dfebe16 Mon Sep 17 00:00:00 2001 From: Julien Schneider Date: Wed, 31 Jan 2024 14:28:41 +0100 Subject: [PATCH 2/4] fix: improve error handler responses --- .../src/lib/app-error-handler.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 487f9a4983..05d6e3f0d0 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 @@ -34,11 +34,10 @@ export class AppErrorHandler implements ErrorHandler { if (badRequestRegexMatch) { this.displayNotification(badRequestRegexMatch[1]); } + + this.testInvalidRequest(error.error.error); } else if (typeof error.error === 'string') { - const invalidRequestRegexMatch = error.error.match(/\((.*)\)$/); - if (invalidRequestRegexMatch) { - this.displayNotification(invalidRequestRegexMatch[1]); - } + this.testInvalidRequest(error.error); } else if (error.error.message) { this.displayNotification(error.error.message); } @@ -71,4 +70,12 @@ export class AppErrorHandler implements ErrorHandler { private displayNotification(message: string) { this._notification.openSnackBar(message, 'error'); } + + // TODO ask the backend to uniformize their response, so that this method is only called once. + private testInvalidRequest(error: string) { + const invalidRequestRegexMatch = error.match(/\((.*)\)$/); + if (invalidRequestRegexMatch) { + this.displayNotification(invalidRequestRegexMatch[1]); + } + } } From ee6ca9db4fd8a2be87a520a7b1dbdb6262337534 Mon Sep 17 00:00:00 2001 From: Julien Schneider Date: Wed, 31 Jan 2024 14:42:08 +0100 Subject: [PATCH 3/4] fix: pass test --- .../app-config/src/lib/app-config/app-config.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/vre/shared/app-config/src/lib/app-config/app-config.service.spec.ts b/libs/vre/shared/app-config/src/lib/app-config/app-config.service.spec.ts index 8139f806b8..26323f1137 100644 --- a/libs/vre/shared/app-config/src/lib/app-config/app-config.service.spec.ts +++ b/libs/vre/shared/app-config/src/lib/app-config/app-config.service.spec.ts @@ -89,7 +89,7 @@ describe('AppConfigService with prod config', () => { geonameToken: 'geoname_token', iriBase: 'http://rdfh.ch', instrumentation: { - environment: 'production', + environment: 'prod', rollbar: { enabled: true, accessToken: 'rollbar_token', From b44628c80188b6fe79ee4cb71c38f7319e5a1366 Mon Sep 17 00:00:00 2001 From: IrKa Date: Wed, 31 Jan 2024 14:52:08 +0100 Subject: [PATCH 4/4] fix: case insensitive shortcodeExistsValidator --- .../reusable-project-form/shortcode-exists.validator.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/dsp-app/src/app/project/reusable-project-form/shortcode-exists.validator.ts b/apps/dsp-app/src/app/project/reusable-project-form/shortcode-exists.validator.ts index 17ee1c540b..78134f1e6f 100644 --- a/apps/dsp-app/src/app/project/reusable-project-form/shortcode-exists.validator.ts +++ b/apps/dsp-app/src/app/project/reusable-project-form/shortcode-exists.validator.ts @@ -1,4 +1,4 @@ -import { AbstractControl, ValidatorFn, ValidationErrors } from '@angular/forms'; +import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'; /** * shortcodeValidator: Validate the shortcode value against @@ -7,6 +7,8 @@ import { AbstractControl, ValidatorFn, ValidationErrors } from '@angular/forms'; */ export function shortcodeExistsValidator(shortcodes: string[]): ValidatorFn { return (control: AbstractControl): ValidationErrors | null => { - return shortcodes.includes(control.value) ? { shortcodeExists: true } : null; + return shortcodes.some(e => e.toLowerCase().search(control.value.toLowerCase()) !== -1) + ? { shortcodeExists: true } + : null; }; }