added common error handling function
This commit is contained in:
parent
b72adf92d5
commit
8f3dbe0ccd
|
@ -1,14 +1,25 @@
|
|||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
@Injectable()
|
||||
export class HttpErrorHandlingService {
|
||||
constructor(
|
||||
protected language: TranslateService
|
||||
protected language: TranslateService,
|
||||
protected uiNotificationService: UiNotificationService,
|
||||
) {
|
||||
}
|
||||
|
||||
handleBackedRequestError(errorResponse: HttpErrorResponse, messageOvverrides?: Map<number, string>) {
|
||||
const error: HttpError = this.getError(errorResponse);
|
||||
if (error.statusCode === 404) {
|
||||
this.uiNotificationService.snackBarNotification(messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : 'NOT-FOUND', SnackBarNotificationLevel.Warning);
|
||||
} else {
|
||||
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
getError(errorResponse: HttpErrorResponse): HttpError {
|
||||
const error: HttpError = new HttpError();
|
||||
error.statusCode = errorResponse.status;
|
||||
|
|
Loading…
Reference in New Issue