Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various fixes #1420

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]);
}
}
}