문제

내가 처리하려고하는 경우는 다음과 같습니다.

  • 요청이 실행되고 응답이 인증 토큰이 만료되었음을 나타냅니다
  • 새로 고침 토큰 요청 보내기
  • 새로 고침 토큰 요청이 성공하면 원래 요청을 다시 시도하십시오.

이것은 호출 활동, 조각 ... 등에서 투명해야합니다. 발신자의 관점에서 한 번의 요청, 한 응답입니다.

okhttpclient를 직접 사용할 때 전에이 흐름을 얻었지만이를 개조에서 달성하는 방법을 모르겠습니다.

어쩌면이 열려있는 이슈

개조에서이를 달성 할 수있는 직선적 인 방법이 없으면이를 구현하는 가장 좋은 방법은 무엇입니까?기본 리스너 클래스?

저는 Robospice를 사용하여 개장 할 수 있습니다.

도움이 되었습니까?

해결책

로봇의 사용 이후로, 나는 추상 BaseRequestListener를 생성하여 이것을 끝내었다.

public abstract class BaseRequestListener<T> implements RequestListener<T> {

    @Override
    public void onRequestFailure(SpiceException spiceException) {
        if (spiceException.getCause() instanceof RetrofitError) {
            RetrofitError error = (RetrofitError) spiceException.getCause();
            if (!error.isNetworkError() 
                && (error.getResponse().getStatus() == INVALID_ACCESS_TOKEN_STATUS_CODE)) {
                //I'm using EventBus to broadcast this event,
                //this eliminates need for a Context
                EventBus.getDefault().post(new Events.OnTokenExpiredEvent());
                //You may wish to forward this error to your listeners as well,
                //but I don't need that, so I'm returning here.
                return;
                }
         }
         onRequestError(spiceException);
    }

    public abstract void onRequestError(SpiceException spiceException);
}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top