2014-03-25 6 views
4

Retrofit 및 OKHttp와 함께 Android에서 Robospice를 사용하고 있습니다. Robospice RequestListener를 사용하여 응답에 큰 영향을 미치는 모든 작품이 다시 액티비티로 전달되었습니다. 문제는 연결 시간이 초과되거나 다른 네트워크 문제 일 경우에만 오류를 반환한다는 것입니다. 401이 반환되면 JSON을 MobileAppSetup POJO로 구문 분석 할 수 없으므로 null 응답으로 성공으로 분류됩니다.Retrofit & OKHttp의 200 응답 이외의 다른 것을 Robospice에서 오류로 처리하려면 어떻게해야합니까?

나는 응답에 널 (null) 검사를 수행하는 데 순간

하지만 난 그게 서버 오류 인 경우 그 이유가 무엇인지 모른다 또는 유효한 401

public final class HTTPRequestListener implements RequestListener<MobileAppSetup> { 

    @Override 
    public void onRequestFailure(SpiceException spiceException) { 
     Log.d("", "failure:"+ spiceException); 
     loginProgress.hide(); 

    } 

    @Override 
    public void onRequestSuccess(final MobileAppSetup response) { 
     Log.d("","success. Data: "+response); 

     if(response==null) 
      showDialog("Error logging in", "Please check your username and password and try again.", ""); 

     loginProgress.hide(); 

     postLoginProcess(response); 

    } 
} 

나는이를 전달할 필요가 없습니다 오류를 onRequestFailure 콜백에 전달하여 제대로 처리 할 수 ​​있습니다. Robospice가 오류로 간주해야하는 오류 코드를 지정하는 방법이 있습니까? 나는 그것이 어떤 종류의 커스텀 에러 핸들러를 추가하는 것을 포함한다고 생각하지만 현재로서는 해결책을 찾지 못한다.

+0

정말 Retrofit 포럼에서 찾아 볼 항목입니다. RS에만 느슨하게 관련되어 있습니다. – Snicolas

+0

@ Snicolas okhttp 클라이언트 버그로 인해 최신 최신 버전을 사용해 보는 것이 좋습니다. –

답변

2

이것은 OKHTTP 클라이언트의 버그로 인한 것입니다. possible bug! 난 당신이 square/okhttp에서 새로운 okhttp jar 파일을 다운로드하는 것이 좋습니다

Problem is When the server answers with a 401 Unauthorized responses, the Callback object calls its failure() method..

When the server returns with the 401 status, the RetrofitError response object is null, and the networkError flag is set to true, making it impossible for the app to check error.getResponse().getStatus() I believe the error lies on the http client. When using OkClient I get this error: java.io.IOException: No authentication challenges found

다시 프로젝트를 실행! 또는 okhttp 대신 다른 클라이언트로 시도하십시오.