Skip to content

Commit

Permalink
Fix StackOverFlowError due to interceptors being added in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh9 committed Oct 24, 2018
1 parent 5aa8ef4 commit 0dfc2c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public <S> S createService(@Nonnull final Class<S> serviceClass,
public <S> S createService(@Nonnull final Class<S> serviceClass,
@Nullable final AuthHeaders headers) {

httpClient.interceptors().clear(); // Fix StackOverFlowError

enableAuthentication(headers);
if (log.isDebugEnabled()) {
enableHttpLogging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import okhttp3.Response;

import java.io.IOException;
import java.util.Objects;

/**
* Retrofit2 interceptor to add common authentication headers to every request.
Expand All @@ -54,4 +55,18 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = builder.build();
return chain.proceed(request);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AuthenticationInterceptor that = (AuthenticationInterceptor) o;
return Objects.equals(authToken, that.authToken) &&
Objects.equals(apiKey, that.apiKey);
}

@Override
public int hashCode() {
return Objects.hash(authToken, apiKey);
}
}

0 comments on commit 0dfc2c3

Please sign in to comment.