Base solution for your next web application
Open Closed

Angular 6: Override @abp/abpHttpConfiguration/handleUnAuthorizedRequest #6966


User avatar
0
larsfk created

Hi!

Im trying to override the method handleUnAuthorizedRequest which is in node_modules/abp/abpHttpConfiguration. I have tried googling and some class extentions, but cannot figure it out...

I tried adding a class in "root.modules.ts" and build "MyAboHttpConfiguration" from there to inject in "AbpHttpInterceptor" (or MyAbpHttpInterceptor), but there is some dependencies that I imagine will be difficault to instanciate. And forking the project can cause some trouble in the future I guess...

Would be nice if someone have a tips to where to go forward with this.


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi @larsfk Try this?

    let abpHttpConfiguration =  injector.get(AbpHttpConfiguration);
    abpHttpConfiguration.handleUnAuthorizedRequest = function(messagePromise: any, targetUrl?: string) {
    	const self = this;
    	if (messagePromise) {
    		messagePromise.done(() => {
    			this.handleTargetUrl(targetUrl || '/');
    		});
    	} else {
    		self.handleTargetUrl(targetUrl || '/');
    	}
    };
    
  • User Avatar
    0
    larsfk created

    That work well! Thank you!

    But handleUnAuthorizedRequest is not the method that triggers the popup with error when user is timed out. Trying to figure it out now.

  • User Avatar
    0
    aaron created
    Support Team

    Which error is that?

  • User Avatar
    0
    larsfk created

    This one, its a 200, but with an error. I rewrote abpHttpConfiguration.handleAbpResponse to check if the error.unAuthorized = true, if so the application will log the user out.

  • User Avatar
    0
    maliming created
    Support Team

    @larsfk Is it convenient to share your complete project code? [email protected]

  • User Avatar
    0
    larsfk created

    I will ask my customer if thats okey for them. Do you want to see all of the code or just the part we have been working on here?

  • User Avatar
    0
    maliming created
    Support Team

    Or you can use Zero's Demo project to reproduce the problems you encountered.