2014-10-03 3 views
1

모든 상점에 일부 논리를 추가하려고합니다. 이 로직을 앱 스토어를 통해 모두 정의 된 로직보다 먼저 실행하기를 원합니다.요청이 실패한 경우 JSONP 프록시 콜백에서 응답을받을 수 없습니다.

기본적으로 서버의 응답을 살펴보고 싶습니다. 그렇지 않다면, 어떤 일이 일어나기를 원한다면 this.callParent()으로 전화하십시오.

내가 원하는 것을 할 듯하지만, 기존의 지금 여기에 4.2.1

http://www.learnsomethings.com/2011/09/01/adding-some-error-detection-to-all-your-extjs-stores-with-one-simple-block-of-code/

위해 일하는 내가 4.2.1에서 할 무엇을하지 그것은

Ext.define('App.overrides.Data.Store', { 
    override: 'Ext.data.Store', 
    load: function (options) { 
     if (options != null) { 
      options.callback = storeLoad; 
     } 
     this.callParent(arguments); 
    } 
}); 

storeLoad: function (records, operation, success) { 
    // operation.response is undefined on failures...  
} 
을 작동하는 것 같군

하지만 위의 설명에서 언급 한 것처럼 요청이 400,401,500 등의 코드로 실패한 경우 operation.response을 얻을 수 없습니다. 내가 ExtJS에 내가 원하는 문자열 오류를 반환하도록되어 부하를 생성하는 정확한 URL을 검색하면

,이 얻을 :

Ext.data.JsonP.callback4({"Message":"The string!"}) 

이 출력은 내 .NET 웹 API 백엔드에 의해 반환됩니다

actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, PortalResources.THE_STRING); 

내가 변경하는 경우 HttpStatusCodeOK에, 나는 다음 위의 storeLoad에 응답을 얻을 수 있지만 것없는 상태 <> (200)

경우

응답을 올바르게 반환하지 않는 백엔드라고 생각했지만 ExtJS 및/또는 내 이해가 문제인 것처럼 보입니다. 서버가 <> 200의 상태를 반환 할 때부터 내 저장소/프록시가 정의 된 방법이라고 생각합니다. Chrome의 디버거에서 응답 내용을 보지 못합니다.

여기 내 상점 중 하나입니다 :

Ext.define('Customer_Portal_UI.store.Contact', { 
    extend: 'Ext.data.Store', 
    model: 'Customer_Portal_UI.model.Contact', 
    limitParam: false, 
    pageParam: false, 
    startParam: false 
}); 

//....... 

Ext.create('Customer_Portal_UI.store.Contact', { 
    storeId: 'myContactStore', 
    proxy: { 
     type: 'jsonp', 
     url: this.Urls.contactGetAllApiUrl, 
     headers: { 'Content-type': 'application/json' }, 
     reader: { type: 'json', root: 'Contacts' } 
    } 
}); 

나는 재정의 in there 언급했지만, 같은 문제. 응답은 실패시 정의되지 않습니다. 프레임 워크 체인에서 모든 단계를 크롤링했으며이를 수행하기 위해 적절한 재정의를 찾지 못하는 것 같습니다.

아이디어가 있으십니까?

답변

0

바닐라 Ajax 프록시로 전환 했으므로 이제는 실패한 요청에 대해 응답 텍스트를 올바르게 검색 할 수 있습니다.

Ext.Ajax.on('requestexception', function (conn, response, options) { 
     //If an AJAX request receives this response text & status, log the user out. 
     //regardless of the resource that was queried 
     if (response.responseText == GlobalVars.loginError && response.status == 408) { 

      //the following stops extra logic from executing (if you had configured a 'failure' option on your request in the controller) 
      delete options.failure; 
      delete options.callback; 

      //show the user a message box with an OK button that when clicked logs the user out... 
      Utils.maxIdleReached(); 
     } 
     else { 
      //do nothing... 
      //let controller logic do it's thing then as individual store/requests have 'failure' options configured for each.... 
     } 
}); 

이 그들이 상점 부하를 통해 수행되었는지 예외 (400의 상태 코드를받은 요청, 401, 408, 404, 500 등)를 잡는다 :

은 내가하고 결국 무엇인가 또는 보통 Ext.Ajax.request.

관련 문제