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; }; } 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..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 @@ -28,12 +28,19 @@ 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]); + } + + this.testInvalidRequest(error.error.error); + } else if (typeof error.error === 'string') { + this.testInvalidRequest(error.error); + } else if (error.error.message) { + this.displayNotification(error.error.message); + } return; } @@ -63,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]); + } + } }