Skip to content

Instantly share code, notes, and snippets.

@johnwatsondev
Forked from polbins/gist:437297ed7587c100e57d
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnwatsondev/4d06fd00d6057baa047c to your computer and use it in GitHub Desktop.
Save johnwatsondev/4d06fd00d6057baa047c to your computer and use it in GitHub Desktop.
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(mRefreshAndRetryInterceptor);
mRestAdapter = new RestAdapter.Builder()
...
.setClient(new OkClient(okHttpClient))
.build();
private final Interceptor mRefreshAndRetryInterceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
if (response.code() == 401) {
Request newRequest = reWriteRequestWithNewToken(request);
response = chain.proceed(newRequest);
}
return response;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment