angularjs - How to resend request when not authorized -



angularjs - How to resend request when not authorized -

i implemented authinterceptorservice when response not authorize send request new token , want resend previoes request. need store somewhere , resend, best way it?

var _responseerror = function (rejection) { if (rejection.status === 401) { var authservice = $injector.get('authservice'); var authdata = localstorageservice.get('authorizationdata'); if (authdata) { authservice.refreshtoken().then(function (response) { //redirect original request }, function (err) { $location.path('/login'); }); } authservice.logout(); $location.path('/login'); } homecoming $q.reject(rejection); }

why not create own request?

// define original request var originalrequest = function( input ){ $http.post( 'url' , info ).then(onsuccess, _responseerror); }

then in _responseerror function, phone call original request

var _responseerror = function (rejection) { if (rejection.status === 401) { var authservice = $injector.get('authservice'); var authdata = localstorageservice.get('authorizationdata'); if (authdata) { authservice.refreshtoken().then(function (response) { //redirect original request originalrequest( input ); }, function (err) { $location.path('/login'); }); } authservice.logout(); $location.path('/login'); } homecoming $q.reject(rejection); }

also, on failure, original configuration of request, utilize that...

if (authdata) { authservice.refreshtoken().then(function (response) { //redirect original request $http.post(rejection.config).then( ... , ... ); }, function (err) { $location.path('/login'); }); }

angularjs

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -