From 53c2e886890f6bdc8fa1f1800aea7fb2a7f8c94e Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Fri, 13 Jul 2018 22:22:26 +0300 Subject: [PATCH] notify library ID conflict (#509) --- src/app/dialogs/library/library.dialog.ts | 12 +++++++++++- src/assets/i18n/en.json | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/dialogs/library/library.dialog.ts b/src/app/dialogs/library/library.dialog.ts index e33ec4b09..3fb071319 100644 --- a/src/app/dialogs/library/library.dialog.ts +++ b/src/app/dialogs/library/library.dialog.ts @@ -112,7 +112,7 @@ export class LibraryDialogComponent implements OnInit { this.success.emit(folder); dialog.close(folder); }, - (error) => this.error.emit('LIBRARY.ERRORS.GENERIC') + (error) => this.handleError(error) ); } @@ -137,4 +137,14 @@ export class LibraryDialogComponent implements OnInit { .replace(/[\s]/g, '-') .replace(/[^A-Za-z0-9-]/g, ''); } + + private handleError(error: any): any { + const { error: { statusCode } } = JSON.parse(error.message); + + if (statusCode === 409) { + this.form.controls['id'].setErrors({ message: 'LIBRARY.ERRORS.CONFLICT' }); + } + + return error; + } } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 62d61ab4d..2d6155afd 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -287,7 +287,8 @@ }, "ERRORS": { "GENERIC": "There was an error", - "EXISTENT_SITE": "ID already used (it might be in the trashcan).", + "EXISTENT_SITE": "This Site ID isn't available. Try a different one", + "CONFLICT": "ID already used (it might be in the trashcan).", "ID_TOO_LONG": "Use 72 characters or less for the URL name", "DESCRIPTION_TOO_LONG": "Use 512 characters or less for description", "TITLE_TOO_LONG": "Use 256 characters or less for title",