From 8f3dbe0ccd13cc8b186ed80067355a19a38176a5 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 30 May 2024 10:57:34 +0300 Subject: [PATCH] added common error handling function --- .../error-handling/http-error-handling.service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts b/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts index f8c7fafa5..5d30d8f8f 100644 --- a/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts +++ b/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts @@ -1,21 +1,32 @@ 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) { + 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; error.messages = this.parseMessages(error.statusCode, errorResponse); try { error.errorCode = + errorResponse.error.code; - } catch {} + } catch { } // if (error && error.error && error.error.error) { // errorMsg = error.error.error;