Improved error toaster

This commit is contained in:
Adina Țeudan 2021-10-19 20:06:05 +03:00
parent 127c47576b
commit dfd4a420c8
4 changed files with 5 additions and 2 deletions

View File

@ -0,0 +1 @@
export const CONFLICT_ERROR_CODE = 409;

View File

@ -10,7 +10,7 @@ export class ErrorMessageService {
getMessage(error: HttpErrorResponse, defaultMessage?: string): string {
return defaultMessage
? (this._translateService.instant(defaultMessage) as string) + this._parseErrorResponse(error)
? (this._translateService.instant(defaultMessage, { error: this._parseErrorResponse(error) }) as string)
: this._parseErrorResponse(error);
}

View File

@ -3,3 +3,4 @@ export * from './toaster.service';
export * from './error-message.service';
export * from './generic.service';
export * from './composite-route.guard';
export * from './constants';

View File

@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
import { HttpErrorResponse } from '@angular/common/http';
import { filter } from 'rxjs/operators';
import { ErrorMessageService } from './error-message.service';
import { CONFLICT_ERROR_CODE } from './constants';
const enum NotificationType {
SUCCESS = 'SUCCESS',
@ -52,7 +53,7 @@ export class Toaster {
error(message: string, options?: Partial<ErrorToasterOptions>): ActiveToast<unknown> {
let resultedMsg;
if (options?.error) {
if (options?.error && options.error.status !== CONFLICT_ERROR_CODE) {
resultedMsg = this._errorMessageService.getMessage(options.error, message);
} else {
resultedMsg = this._translateService.instant(message, options?.params) as string;