How to avoid $compile:tpload errors on 401 status code response

后端 未结 3 894
抹茶落季
抹茶落季 2021-02-02 15:58

We are developing a Single Page Application with AngularJS and ASP.NET MVC Json Rest API.

When an unauthenticated client tries to navigate to a private route (Ex: /F

3条回答
  •  佛祖请我去吃肉
    2021-02-02 16:30

    You should be able to intercept the call for the template by status and url.

    Plunker

    app.config(function($httpProvider) {
    
      var interceptor = function($location, $log, $q) {
    
          function success(response) {
            // The response if complete
            $log.info(response);
            return response;
          }
    
          function error(response) {
            // The request if errors
            $log.error(response);
            return $q.reject(response);
          }
    
          return function(promise) {
            return promise.then(success, error);
          }
        }
    
      $httpProvider.responseInterceptors.push(interceptor);
    
    });
    

提交回复
热议问题