Open Closed

redirect to login page without exception show if user not logined #5096


User avatar
0
hamidsharifi created

Hi When a user is not login the app show the error box and after click on close error box redirect to login page. i want to redirect to login page without show error box. the error box is like below


1 Answer(s)
  • User Avatar
    0
    masum.ulu created
    Support Team Angular Developer

    Hello Hamid,

    Which type UI you using ? If it's angular you can customize specific error code check the documentation

    Example

    custom-error.handler.ts

    //app/shared/handlers/custom-error.handler.ts
    import { Injector } from '@angular/core';
    import { HttpErrorResponse } from '@angular/common/http';
    import { throwError } from 'rxjs';
    import { AuthService } from '@abp/ng.core';
    
    export function handleHttpErrors(injector: Injector, httpError: HttpErrorResponse) {
      if (httpError.status === 401) {
        injector.get(AuthService).navigateToLogin();
        return;
      }
    
      return throwError(() => httpError);
    }
    

    app.module.ts

    //app/app.module
    import {HTTP_ERROR_HANDLER} from '@abp/ng.theme.shared';
    import {handleHttpErrors} from './shared/handlers/custom-error.handler';
    //Other imports..
    
    @NgModule({
      imports: [
       //Modules
      ],
      providers: [
        APP_ROUTE_PROVIDER,
        //ADD THE BELOW CODE
        { provide: HTTP_ERROR_HANDLER, useValue: handleHttpErrors }
      ],
      declarations: [],
      bootstrap: [],
    })
    export class AppModule {}
    
    
    

    Result

    As you can see I'm directly redirecting to login

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11