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 Expert

    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

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on May 21, 2025, 07:50