2016-09-15 2 views
0

각도 인터셉터를 사용 중이고 메시지에서 500 개의 오류 (내부 서버 오류)를 가져 오려고합니다.각도 인터셉터 - 500 오류에서 메시지 가져 오기

문제는 내가 요격 내부 responseError에 (아래 스크린 샷)을 rejection.data에서 전체 HTML을 얻고 있다는 것이다.

나는 구성해야한다고 읽었습니다. web.config하지만 여전히 전체 HTML을 얻고 있습니다. 나는 그저 메시지를 듣고 싶다.

그렇게 할 수 있습니까?

각도 인터셉터 :

app.config(['$httpProvider', function ($httpProvider) { 

    $httpProvider.interceptors.push(function ($q, $rootScope) { 

     return { 
      request: function (config) { 

       //the same config/modified config/a new config needs to be returned. 
       return config; 
      }, 
      requestError: function (rejection) { 

       //Initializing error list 
       if ($rootScope.errorList == undefined) { 
        $rootScope.errorList = []; 
       } 

       $rootScope.errorList.push(rejection.data); 

       //It has to return the rejection, simple reject call doesn't work 
       return $q.reject(rejection); 
      }, 
      response: function (response) { 

       //the same response/modified/or a new one need to be returned. 
       return response; 
      }, 
      responseError: function (rejection) { 

       //Initializing the error list 
       if ($rootScope.errorList == undefined) { 
        $rootScope.errorList = []; 
       } 

       //Adding to error list 
       $rootScope.errorList.push(rejection.data); 

       //It has to return the rejection, simple reject call doesn't work 
       return $q.reject(rejection); 
      } 
     }; 
    }); 
}]); 

의 Web.config 편집

<system.webServer> 
    <httpErrors existingResponse="PassThrough" errorMode="Detailed"></httpErrors> 
</system.webServer> 

Image

: 나는 예외 스냅 샷에서 메시지를 얻으려면

Image2

+0

당신은 data.message 점점거야? – Disha

+0

아무 것도. 왜냐하면 데이터에서 나는 첫 번째 이미지 에서처럼 전체 HTML을 가지고 있기 때문입니다. 나는 편집을했다. –

답변

0

500 개의 오류 (내부 서버 오류)에서 메시지를 가져오고 싶습니다. {string|Object} - - 응답 본체

  • 데이터 :

    응답 개체가이 속성이 있습니다 : 워드 프로세서

    responseError: function (errorResponse) { 
    
        //Initializing the error list 
        if ($rootScope.errorList == undefined) { 
         $rootScope.errorList = []; 
        } 
    
        //Adding to error list 
        $rootScope.errorList.push(errorResponse.statusText); 
    
        //It has to return the rejection, simple reject call doesn't work 
        return $q.reject(errorResponse); 
    } 
    

    :

    사용 response.statusText 메시지를 얻을 수 변환 함수로 변환됩니다.

  • 상태 - {number} - 응답의 HTTP 상태 코드입니다.
  • 헤더 - {function([headerName])} - 헤더 게터 기능.
  • config - {Object} - 요청을 생성하는 데 사용 된 구성 객체입니다.
  • statusText - {string} - 응답의 HTTP 상태 텍스트.

-AngularJS $http Service API Reference -- General Usage

관련 문제