RED-8850: show backend error message.
This commit is contained in:
parent
49a9459a35
commit
fa9f84e5ec
@ -34,11 +34,7 @@ export class AddEntityDialogComponent extends BaseDialogComponent {
|
||||
}
|
||||
|
||||
async save(): Promise<void> {
|
||||
try {
|
||||
await this._addEditEntityComponent.save();
|
||||
this._dialogRef.close(true);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
await this._addEditEntityComponent.save();
|
||||
this._dialogRef.close(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,16 +37,8 @@ export class EntityInfoComponent {
|
||||
return !this._addEditEntityComponent || this._addEditEntityComponent.form?.invalid || !this._addEditEntityComponent.changed;
|
||||
}
|
||||
|
||||
get changed(): boolean {
|
||||
return this._addEditEntityComponent.changed;
|
||||
}
|
||||
|
||||
async save(): Promise<void> {
|
||||
try {
|
||||
await this._addEditEntityComponent.save();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
await this._addEditEntityComponent.save();
|
||||
}
|
||||
|
||||
revert(): void {
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { EntitiesService, QueryParam, Toaster } from '@iqser/common-ui';
|
||||
import { List } from '@iqser/common-ui/lib/utils';
|
||||
import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, IDictionary, IUpdateDictionary, SuperTypes } from '@red/domain';
|
||||
import { DossierDictionariesMapService } from '@services/entity-services/dossier-dictionaries-map.service';
|
||||
import { FALLBACK_COLOR } from '@utils/constants';
|
||||
import { firstValueFrom, forkJoin, Observable, throwError } from 'rxjs';
|
||||
import { catchError, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { firstValueFrom, forkJoin, Observable } from 'rxjs';
|
||||
import { map, switchMap, tap } from 'rxjs/operators';
|
||||
import { IMAGE_CATEGORIES } from '../../modules/file-preview/utils/constants';
|
||||
import { DictionariesMapService } from './dictionaries-map.service';
|
||||
import { DossierTemplateStatsService } from './dossier-template-stats.service';
|
||||
@ -69,7 +68,6 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
|
||||
const url = `${this._defaultModelPath}/type/${type}/${dossierTemplateId}`;
|
||||
const queryParams = dossierId ? [{ key: 'dossierId', value: dossierId }] : undefined;
|
||||
const request = this._post(body, url, queryParams).pipe(
|
||||
catchError((error: unknown) => this.#addUpdateDictionaryErrorToast(error)),
|
||||
switchMap(() => this.loadDictionaryDataForDossierTemplate(dossierTemplateId)),
|
||||
switchMap(() => this._dossierTemplateStatsService.getFor([dossierTemplateId])),
|
||||
);
|
||||
@ -80,7 +78,6 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
|
||||
async add(dictionary: IDictionary, dossierId?: string): Promise<unknown> {
|
||||
const queryParams = dossierId ? [{ key: 'dossierId', value: dossierId }] : undefined;
|
||||
const request = this._post(dictionary, `${this._defaultModelPath}/type`, queryParams).pipe(
|
||||
catchError((error: unknown) => this.#addUpdateDictionaryErrorToast(error)),
|
||||
switchMap(() => this.loadDictionaryDataForDossierTemplate(dictionary.dossierTemplateId)),
|
||||
switchMap(() => this._dossierTemplateStatsService.getFor([dictionary.dossierTemplateId])),
|
||||
);
|
||||
@ -291,15 +288,4 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
|
||||
const url = `${this._defaultModelPath}/delete/${type}/${dossierTemplateId}`;
|
||||
return firstValueFrom(this._post(entries, url, queryParams));
|
||||
}
|
||||
|
||||
#addUpdateDictionaryErrorToast(error: HttpErrorResponse | unknown): Observable<never> {
|
||||
if ((error as HttpErrorResponse).status === HttpStatusCode.Conflict) {
|
||||
this._toaster.error(_('add-edit-entity.error.entity-already-exists'));
|
||||
} else if ((error as HttpErrorResponse).status === HttpStatusCode.BadRequest) {
|
||||
this._toaster.error(_('add-edit-entity.error.invalid-color-or-rank'));
|
||||
} else {
|
||||
this._toaster.error(_('add-edit-entity.error.generic'));
|
||||
}
|
||||
return throwError(() => error);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user