
com.contentful.java.cda.interceptor.ErrorInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk Show documentation
Show all versions of java-sdk Show documentation
Java SDK for Contentful's Content Delivery API.
package com.contentful.java.cda.interceptor;
import com.contentful.java.cda.CDAHttpException;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
/**
* This interceptor will only be used for throwing an exception, once the server returns an error.
*/
public class ErrorInterceptor implements Interceptor {
private final boolean logSensitiveData;
public ErrorInterceptor(boolean logSensitiveData) {
this.logSensitiveData = logSensitiveData;
}
/**
* Intercepts chain to check for unsuccessful requests.
*
* @param chain provided by the framework to check
* @return the response if no error occurred
* @throws IOException will get thrown if response code is unsuccessful
*/
@Override public Response intercept(Chain chain) throws IOException {
final Request request = chain.request();
final Response response = chain.proceed(request);
if (!response.isSuccessful()) {
throw new CDAHttpException(request, response, logSensitiveData);
}
return response;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy