Skip to content

Commit

Permalink
Merge branch 'main' into release-please--branches--main--components--…
Browse files Browse the repository at this point in the history
…DSP-APP
  • Loading branch information
derschnee68 authored Jan 31, 2024
2 parents d809cc1 + d88aa17 commit 63a5403
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractControl, ValidatorFn, ValidationErrors } from '@angular/forms';
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';

/**
* shortcodeValidator: Validate the shortcode value against
Expand All @@ -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;
};
}
27 changes: 21 additions & 6 deletions libs/vre/shared/app-error-handler/src/lib/app-error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]);
}
}
}

0 comments on commit 63a5403

Please sign in to comment.