added common error handling function
This commit is contained in:
parent
b72adf92d5
commit
8f3dbe0ccd
|
@ -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<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;
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue