programing

Angular.js $http 가로채기 "net::ERR_CONNECTION_REFUSED"

lastcode 2023. 4. 2. 10:37
반응형

Angular.js $http 가로채기 "net::ERR_CONNECTION_REFUSED"

다음을 사용하여 웹 사이트의 일반 오류 핸들러를 작성하려고 합니다.$http'가로채기는 하지만 내가 원하는 것을 할 수 없는 것 같아.

요격기를 설치했습니다'response'그리고.'responseError'그러나 서버가 오프라인 상태이거나 응답하지 않을 때는 호출되지 않습니다(net::ERR_CONNECTION_REFUSED).왜 이런 일이 일어나는지 알겠어요. 가로채기엔 반응이 없어요.

이러한 오류를 검출하는 일반적인 방법이 있는지 알고 싶습니다.$httpPromiseerror콜백이 표시됩니다.

ResponseError 상태를 확인할 수 있습니다.API가 0(Angular 1.3.18까지) 또는 -1(Angular 1.3.19 이후)인 경우:

angular.module("services.interceptor", arguments).config(function($httpProvider) {
     $httpProvider.interceptors.push(function($q) {
        return {
          responseError: function(rejection) {
                if(rejection.status <= 0) {
                    window.location = "noresponse.html";
                    return;
                }
                return $q.reject(rejection);
            }
        };
    });
});

언급URL : https://stackoverflow.com/questions/23914893/angular-js-http-intercept-neterr-connection-refused

반응형