Improved error toaster
This commit is contained in:
parent
127c47576b
commit
dfd4a420c8
1
src/lib/services/constants.ts
Normal file
1
src/lib/services/constants.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const CONFLICT_ERROR_CODE = 409;
|
||||||
@ -10,7 +10,7 @@ export class ErrorMessageService {
|
|||||||
|
|
||||||
getMessage(error: HttpErrorResponse, defaultMessage?: string): string {
|
getMessage(error: HttpErrorResponse, defaultMessage?: string): string {
|
||||||
return defaultMessage
|
return defaultMessage
|
||||||
? (this._translateService.instant(defaultMessage) as string) + this._parseErrorResponse(error)
|
? (this._translateService.instant(defaultMessage, { error: this._parseErrorResponse(error) }) as string)
|
||||||
: this._parseErrorResponse(error);
|
: this._parseErrorResponse(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,3 +3,4 @@ export * from './toaster.service';
|
|||||||
export * from './error-message.service';
|
export * from './error-message.service';
|
||||||
export * from './generic.service';
|
export * from './generic.service';
|
||||||
export * from './composite-route.guard';
|
export * from './composite-route.guard';
|
||||||
|
export * from './constants';
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { filter } from 'rxjs/operators';
|
import { filter } from 'rxjs/operators';
|
||||||
import { ErrorMessageService } from './error-message.service';
|
import { ErrorMessageService } from './error-message.service';
|
||||||
|
import { CONFLICT_ERROR_CODE } from './constants';
|
||||||
|
|
||||||
const enum NotificationType {
|
const enum NotificationType {
|
||||||
SUCCESS = 'SUCCESS',
|
SUCCESS = 'SUCCESS',
|
||||||
@ -52,7 +53,7 @@ export class Toaster {
|
|||||||
|
|
||||||
error(message: string, options?: Partial<ErrorToasterOptions>): ActiveToast<unknown> {
|
error(message: string, options?: Partial<ErrorToasterOptions>): ActiveToast<unknown> {
|
||||||
let resultedMsg;
|
let resultedMsg;
|
||||||
if (options?.error) {
|
if (options?.error && options.error.status !== CONFLICT_ERROR_CODE) {
|
||||||
resultedMsg = this._errorMessageService.getMessage(options.error, message);
|
resultedMsg = this._errorMessageService.getMessage(options.error, message);
|
||||||
} else {
|
} else {
|
||||||
resultedMsg = this._translateService.instant(message, options?.params) as string;
|
resultedMsg = this._translateService.instant(message, options?.params) as string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user