Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
http-error-handler.service.ts 1.24 KiB
Newer Older
  • Learn to ignore specific revisions
  • import {Injectable} from '@angular/core';
    import {HttpErrorResponse} from "@angular/common/http";
    import {NavigationService} from "../../window/sidenav/navigation-model.service";
    import {AlertMessageService} from "../alert-message/alert-message.service";
    
    @Injectable()
    export class HttpErrorHandlerService {
    
      constructor (private navigationService: NavigationService,
    
                   private alertMessageService: AlertMessageService) {
    
      }
    
      public logoutOnInvalidSessionError(err: any): boolean {
        if (err instanceof HttpErrorResponse) {
          if (err.status === 401) {
            this.navigationService.navigateToLogin();
    
            this.alertMessageService.error("You have been logged out because of inactivity or missing access permissions.")
    
    
      public handleHttpError(err: any) {
        if (err instanceof HttpErrorResponse) {
          if (this.logoutOnInvalidSessionError(err)) {
            return;
          }
          if (err.status === 0) {
            this.alertMessageService.error("Server is not reachable. Please try again later.");
          } else {
            this.alertMessageService.error(err.error.errorDescription);
          }
        } else {
          this.alertMessageService.error(err.error?.errorDescription);
        }
    
      }